The global installation NPM package reported an error and did not have permission

Background: npm i npm-check -g when reporting error no permission Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

1. Check the owner of the directory

ls -la /usr/local/lib/node_modules

total 0
drwxr-xr-x   3 root       wheel   96  6 18 12:42 .
drwxrwxr-x   6 anna       admin  192 12 12 15:45 ..
drwxr-xr-x  23 root       wheel  736 12 26  2018 npm

Discover node_The module is under the root, so you transfer it to yourself

2. Look who it is now

whoami

anna

It’s Anna, not root, so change it

3. Change the directory owner (note the user name Anna)

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

Popular science: chown change the owner of the specified file to the specified user or group, parameter - R process all files in the specified directory and its subdirectories.

Similar Posts: