Error: EACCES: permission denied, access '/usr/lib/node_modules' Error: EACCES: permission denied, access '/usr/lib/node_modules' shell shell

Error: EACCES: permission denied, access '/usr/lib/node_modules'


It's not recommended to use sudo with npm install, follow the steps from npmjs official docs instead :)

Make a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

Open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

Back on the command line, update your system variables:

source ~/.profile

Test: Download a package globally without using sudo.

npm install -g typescript

Source: https://docs.npmjs.com/getting-started/fixing-npm-permissions


When installing global packages in ubuntu, you need special write permissions as you are writing to the usr/bin folder. It is for security reasons.

So, everytime you install a global package, use:

sudo npm install -g [package-name]

for your specific case:

sudo npm install -g typescript

When you try it without -g all that you are doing is installing the package locally in whatever folder you are in:

so: npm install typescript will create a node_modules folder in the folder you are in.


I have same issue with webpack server installation on globally, Use steps Solved my issue, my be work for you.

Steps mention above There: Back-up your computer before you start.

Make a directory for global installations:

1. mkdir ~/.npm-global

Configure npm to use the new directory path:

2. npm config set prefix '~/.npm-global'

Open or create a ~/.profile file and add this line:

3. export PATH=~/.npm-global/bin:$PATH

Back on the command line, update your system variables:

4. source ~/.profile

Test: Download a package globally without using sudo.

npm install -g jshint

Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global