69
votes

I am trying to install angular cli but it's show me Missing write access to /usr/local/lib/node_modules so, how can I fix it in my mac i try it may time but, not getting exact answer

 npm WARN checkPermissions Missing write access to /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!   stack:
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! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
12
Have you tried: sudo npm install? - Sergey Kirienko
yes, i try with that - Kundan Kumar Mourya
Can you create any file or folder at this path /usr/local/lib/node_modules manually? Either usually or through sudo. - Sergey Kirienko
No, its auto created while installing node js - Kundan Kumar Mourya
Adding sudo worked for me - ilibilibom

12 Answers

156
votes

Run these commands in a terminal window:

sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
46
votes

I had this issue, I could fixed it by calling sudo on every global install. I wasn't ok with that.

I followed the n package installation advices to be able to install npm packages without sudo.

sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

Answer of @jeduard didn't work for me.

23
votes

Best way to solve your npm install -g issues:

https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

This way, you will never need to use SUDO or change permissions.

Quoting:

  1. Back up your computer.

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

     mkdir ~/.npm-global
    
    
  3. Configure npm to use the new directory path:

     npm config set prefix '~/.npm-global'
    
    
  4. In your preferred text editor, open or create a ~/.profile file and add this line:

     export PATH=~/.npm-global/bin:$PATH
    
    
  5. On the command line, update your system variables:

     source ~/.profile
    
4
votes

Attaching Screenshot Appending sudo before the npm install saved my day.Once you provide your system password, installation should finish smoothly

sudo npm install -g @angular/cli
3
votes

Same problem. I reinstalled the latest version of node via https://nodejs.org/en/download/ instead of using terminal. This resolved the issue.

3
votes

Just add sudo: sudo npm install -g @angular/cli

2
votes

I had a similar issue when trying to install React -- issues with permissions being denied.

This is where SUDO can come in handy, it allows a permitted user to execute a command as the superuser or another user. Think of like "Run as Administrator" on Windows. If you type in the following command, it should allow you to access all of the needed folders with the proper elevated access.

sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

This is also denoted in Dimitri's answer: https://stackoverflow.com/a/60791736/3803726

0
votes

If you're really blocked on installing NPM modules globally (e.g. on some corporate laptop), you could just install them all in a single local folder somewhere and then add the path to node_modules/.bin/ to your PATH environment.

0
votes

I had the same issue.
type this cmd in terminal

sudo nautilus

after that, it opens another file manager that has root access

enter image description here

after that type

    sudo apt install nodejs 
    sudo apt install npm 
    sudo npm install -g npm@latest
    sudo npm install -g @angular/cli
    ng --version
0
votes

I just ran the install command with sudo and FWIW that worked for me :)

-1
votes

Simple, just run the below command
sudo chown -R $USER /usr/local/lib/node_modules

-7
votes

Try using on the terminal

su

It'll ask you for the password, then you can run the command above.