Install any npm packages as global (e.g. npm i -g firebase-tools
or npm i -g npm
) will trigger EACCES: permission denied
error on my Lubuntu 20.04. Even if I run it with sudo
, there is no error but package is not updated.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib' }
npm ERR!
There is a solution to enable installaton via sudo, but I didn't try it.
The global packages seems to be installed at /usr/local/lib/node_modules
which belongs to root. Technically I could do sudo chown -R $(whoami) /usr/local/lib/node_modules
, but npm
package involve others directory whch require chown
as well.
At last I decide to opt for this solution
- Reinstall npm with a node version manager (recommended)
- or Manually change npm’s default directory
I opted for change npm’s default directory
Create a directory for global installations at your home directory
mkdir ~/.npm-global
Configure npm to use the new directory path
npm config set prefix '~/.npm-global'
Edit ~/.profile
or ~/.bashrc
and add the following, depending on your system.
export PATH=~/.npm-global/bin:$PATH
Reload ~/.profile
source ~/.profile
Test global installation
npm i -g npm
Check version
npm -v