8

Can't correct the EACCESS issue from trying to install truffle.

Yes I had installed initially npm via sudo and not nvm but that was corrected -unless who knows what- as per web.

This path did not actually exist so I created it as per a git issue:

/root/.config/truffle/

[root@home config]# ls -la |grep truffle
drwxrwxr-x. 2 root root   6 Jul 14 17:08 truffle

[user@home ~]$ nvm --version
0.34.0

$ npm -v
6.9.0

Assigned full permissions to node_modules:

ll|grep node
drwxrwxrwx. 31 user user 4096 Jul 14 16:58 node_modules

I tried a suggestion from this link:Permission denied when installing npm module.

A user in Ethereum SE has this issue on Ubuntu issue.

Explored the following link and gave full permissions to package-lock in case that was the issue npm notice created a lockfile as package-lock.json. You should commit this file

Tried forcing clear npm cache.

This github user apparently solved it by using sudo: truffle compile error (EACCES: permission denied) on V5 w/ Linux #1212

Install was also attempted as root.

$ sudo npm install -g truffle
/usr/local/lib/nodejs/node-v10.16.0-linux-x64/bin/truffle ->/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/cli.bundled.js

> truffle@5.0.27 postinstall /usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle
> node ./scripts/postinstall.js

Error: EACCES: permission denied, open '/root/.config/truffle/config.json'
You don't have access to this file.

at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at Configstore.get all [as all] (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/~/configstore/index.js:31:1)
at new Configstore (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/~/configstore/index.js:25:31)
at Function.Config.getUserConfig (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-config/index.js:395:1)
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/mnemonics/mnemonic.js:11:1)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at Object.command.command (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/develop.js:2:22)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at Object.module.exports.$schema (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/index.js:9:12)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/cli.js:33:29)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at /usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:65:1
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/cli.bundled.js:71:10)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
Error: Error while attempting to download and cache solc 0.5.8: Command failed: node ./build/cli.bundled.js obtain --solc=0.5.8
Error: EACCES: permission denied, open '/root/.config/truffle/config.json'
You don't have access to this file.

at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at Configstore.get all [as all] (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/~/configstore/index.js:31:1)
at new Configstore (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/~/configstore/index.js:25:31)
at Function.Config.getUserConfig (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-config/index.js:395:1)
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/mnemonics/mnemonic.js:11:1)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at Object.command.command (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/develop.js:2:22)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at Object.module.exports.$schema (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/index.js:9:12)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/packages/truffle-core/cli.js:33:29)
at __webpack_require__ (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:19:1)
at /usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/webpack:/webpack/bootstrap fa1fcd3fc6c4fef3eaf9:65:1
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/build/cli.bundled.js:71:10)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)

at postinstallObtain (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/scripts/postinstall.js:13:11)
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/truffle/scripts/postinstall.js:20:3)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
+ truffle@5.0.27
updated 1 package in 5.873s

A different attempt based on cypress issue

$ sudo npm install --unsafe-perm=true --allow-root truffle
path.js:1077
    path = process.cwd();
                   ^

Error: ENOENT: no such file or directory, uv_cwd
at Object.resolve (path.js:1077:24)
at Function.Module._resolveLookupPaths (internal/modules/cjs/loader.js:534:17)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:629:20)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at /usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js:19:21
at Object.<anonymous> (/usr/local/lib/nodejs/node-v10.16.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js:152:3)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
terdon
  • 3,260
  • 5
  • 33
  • 57
DRP
  • 239
  • 4
  • 16

5 Answers5

5

I was having this problem with not just truffle but other modules as well. For me at least the other solutions listed in this thread worked but they had the side effect that I could only run truffle as super user. I know it may be a bit reckless but my solution was to change ownership of all files in the .config directory to my user. To accomplish this I did the following:

sudo chown myUsername:myUsername -R ~/.config

If you wanted to be a bit more careful about this you could alternatively run

sudo chown myUsername:myUsername ~/.config

sudo chown myUsername:myUsername ~/.config/truffle

sudo chown myUsername:myUsername ~/.config/truffle/config.json

After doing this I was able to run sudo npm i -g truffle. This was a quick fix to all the problems I had previously I hope it works for you!

4

This also occurs when building containers on alpine when installing truffle, I was able to remediate the issue using;

npm i -g --unsafe-perm=true --allow-root truffle

Dockerfile

FROM node:10.17.0-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN apk add -t .gyp --no-cache git python g++ make \
    && npm i -g --unsafe-perm=true --allow-root truffle \
    && apk del .gyp

ENTRYPOINT ["truffle"]

In my initial attempts, installing globally, via npm i -g truffle also resulted in the same EACCES error.

HTH

ramene
  • 61
  • 5
1

Via nvm upgraded node to version v12.6.0, turned off and came back this morning and got truffle installed:

[user@home ~]$ npm install truffle

> truffle@5.0.27 postinstall /home/user/node_modules/truffle
> node ./scripts/postinstall.js

- Fetching solc version list from solc-bin. Attempt #1
- Downloading compiler. Attempt #1
npm WARN saveError ENOENT: no such file or directory, open '/home/user/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/delta/package.json'
npm WARN delta No description
npm WARN delta No repository field.
npm WARN delta No README data
npm WARN delta No license field.

+ truffle@5.0.27
added 27 packages from 439 contributors and audited 34 packages in 125.024s
found 0 vulnerabilities

Tried again globally and no warning messages:

[user@home node_modules]$ npm install -g truffle
/home/user/.nvm/versions/node/v12.6.0/bin/truffle -> /home/user/.nvm/versions/node/v12.6.0/lib/node_modules/truffle/build/cli.bundled.js

> truffle@5.0.27 postinstall /home/user/.nvm/versions/node/v12.6.0/lib/node_modules/truffle
> node ./scripts/postinstall.js

- Fetching solc version list from solc-bin. Attempt #1
+ truffle@5.0.27
added 27 packages from 439 contributors in 5.28s
DRP
  • 239
  • 4
  • 16
  • I still go the same error of `Error: EACCES: permission denied, open '/Users/macbookpro/.config/truffle/config.json'` in mac when using `npm install truffle` – Ender Dec 10 '19 at 05:56
0

My Workaround

Slight mod of @ramene ‘s answer:

sudo su -c "sudo npm i -g --unsafe-perm=true --allow-root truffle"

Worked for me with output:

npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the AP
I surface has changed to use Promises in 1.x.)
/usr/bin/truffle -> /usr/lib/node_modules/truffle/build/cli.bundled.js
> truffle@5.1.22 postinstall /usr/lib/node_modules/truffle
> node ./scripts/postinstall.js
- Fetching solc version list from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #1.
+ truffle@5.1.22
updated 1 package in 21.127s

Hardware Notes

I am using raspbian buster on Raspberry Pi 4 with berryboot.

Output of uname -a:

Linux raspberrypi 4.19.75v64 #1 SMP PREEMPT Sat Oct 5 03:06:01 CEST 2019 aarch64 GNU/Linux
0

This helped for me:

sudo npm install --unsafe-perm -g truffle

Ayan
  • 8,192
  • 4
  • 46
  • 51