问题
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! node v6.9.2
npm ERR! npm v3.10.9
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! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! at Error (native)
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! Please include the following file with any support request:
npm ERR! /Users/apple/npm-debug.log
回答1:
When you use npm install -g
on any platform and you get EACCES
, you are writing to a directory for which you do not have write permission.
Some may recommend using sudo
, but this will lead to more problems in the future. The npm documentation provides steps to fix this.
I highly recommend option 3, using Homebrew to install Node.
回答2:
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.
回答3:
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
回答4:
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
回答5:
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.
回答6:
The answer by Ayush is what I tried at first. Yet the problem persisted. Maybe I didn't do all the steps correctly , I am not sure. So again I looked up Google and found this link https://github.com/angular/angular-cli/issues/7735#issuecomment-345546822. There are two ways to go about solving it. Luckily the first way worked for me. The step that might have made a difference may be compared to what Ayush mentioned above in the answers:
$ echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc
$ source ~/.bashrc
I am using Ubuntu though! Anyways it is solved now. :)
回答7:
Hello Please Follow my guide to install angular 4 from the cli without any permission issues:
Install the angular-cli
globally
sudo npm install -g @angular/cli
Create a new project
ng new my-app --skip-install
Serve the application
sudo chown <username> -R my-app
cd my-app
mkdir node_modules
chmod a+w node_modules
npm install
ng serve --open
回答8:
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
回答9:
Run this command for centos user:
npm install npm@latest -g
it worked for me!!
来源:https://stackoverflow.com/questions/42042300/npm-throws-eacces-error-on-installation-of-angular-cli