I am unable to install Angular Cli globally through npm.
I keep getting this error when I run npm install -g @angular/cli
on macOS:
npm ERR! nod
I fixed the issue by running
sudo npm install -g @angular/cli
After prompting for password enter it.
Then you will be able to install.
Important Note: My answer has vulnerability issues. Giving permissions as root. Use it only after analyzing the effect on your system.
After using
sudo npm install -g PACKAGE-NAME --unsafe-perm=true --allow-root
I still had issues creating a project with the CLI. these commands, allowing permissions, fixed it:
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
This was a great link for me.
https://flaviocopes.com/npm-fix-missing-write-access-error/
once I did this command
sudo chown -R $USER /usr/local/lib/node_modules
in my terminal, the angular CLI install worked perfectly!
create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
update your system variables:
source ~/.profile
Reference: Resolving EACCES permissions errors when installing packages globally
Try using this: 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
Test installing package globally without using sudo.
Now run npm install -g @angular/cli
it should work.
WARNING: Check that $(npm config get prefix)
does not point to /usr
by typing echo $(npm config get prefix)
I solved like that
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Worked for me