Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

What might be causing the error Error: EACCES: permission denied, access '/usr/local/lib/node_modules'?

npm ERR! path /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules' npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules' npm ERR!   errno: -13, npm ERR!   code: 'EACCES', npm ERR!   syscall: 'access', npm ERR!   path: '/usr/local/lib/node_modules' } npm ERR!  npm ERR! Please try running this command again as root/Administrator.  npm ERR! A complete log of this run can be found in: npm ERR!     /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log 
like image 234
hendra dedi Avatar asked Feb 21 '18 16:02

hendra dedi


2 Answers

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use a hidden directory in your home directory.

Back up your computer. On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

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

In your preferred text editor, open or create a

~/.profile

file and add this line:

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

On the command line, update your system variables:

source ~/.profile

To test your new configuration, install a package globally without using sudo

like image 20
Naveen Raju Avatar answered Sep 28 '22 11:09

Naveen Raju


Change your file permissions... Like this

First check who owns the directory

ls -la /usr/local/lib/node_modules 

it is denying access because the node_module folder is owned by root

drwxr-xr-x   3 root    wheel  102 Jun 24 23:24 node_modules 

so this needs to be changed by changing root to your user but first run command below to check your current user How do I get the name of the active user via the command line in OS X?

id -un OR whoami

Then change owner

sudo chown -R [owner]:[owner] /usr/local/lib/node_modules 

OR

sudo chown -R ownerName: /usr/local/lib/node_modules 

OR

sudo chown -R $USER /usr/local/lib/node_modules 
like image 152
okandas Avatar answered Sep 28 '22 11:09

okandas