npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

EACCES: permission denied, access '/root/.npm'

I was trying to install a npm package npm i -g bash-language-server with sudo privileges and after downloading and extracting all file i am getting this error.

Complete Error

$ sudo npm i -g bash-language-server
[sudo] password for terabyte: 
/usr/bin/bash-language-server -> /usr/lib/node_modules/bash-language-server/bin/main.js

> tree-sitter@0.13.23 install /usr/lib/node_modules/bash-language-server/node_modules/tree-sitter
> prebuild-install || node-gyp rebuild

prebuild-install WARN install EACCES: permission denied, access '/root/.npm'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/bash-language-server/node_modules/tree-sitter/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/bash-language-server/node_modules/tree-sitter/.node-gyp'
gyp ERR! System Linux 4.19.24-1-MANJARO
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/lib/node_modules/bash-language-server/node_modules/tree-sitter
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! errno 1
npm ERR! tree-sitter@0.13.23 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the tree-sitter@0.13.23 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-02-25T13_25_39_685Z-debug.log

Are you running the command as root, such as in a Dockerfile?


No dockerfile. I have sudo privileges so i am using sudo to run npm i -g bash-language-server.

Note : some packages like nodemon are being installed with sudo but not this

I had no errors when I installed without sudo (I have write permission to global packages) :

npm i -g bash-language-server

I did reproduce similar errors when I used sudo:

sudo npm i -g bash-language-server

I was able to install without errors by adding --unsafe-perm. I don’t know enough about the package to say whether this is appropriate, and up to you whether to use this.

sudo npm i -g bash-language-server --unsafe-perm

I did find a link with some people having similar looking issue: