Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm throws EACCES error on installation of Angular CLI

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
like image 758
calibre24 Avatar asked Feb 04 '17 15:02

calibre24


People also ask

Will npm install install angular cli?

When you running npm install the Angular CLI gets installed locally for your project. Then, when you run npm start or npm run ng <your command> it will kick off. Then when you run ng <command> in your project directory, for commands like scaffolding - ng g <params> or ng update the global CLI will be in use.

What is Eacces permission denied?

It looks like you're running into permission issues. If you are installing npm-packages then it might possible that you are getting an EACCES error when trying to install a package globally. This means you do not have permission to write to the directories npm uses to store global packages and commands.


2 Answers

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 options to fix this.

I highly recommend using a node version manager like nodenv as the solution.

like image 142
Robin Daugherty Avatar answered Sep 25 '22 23:09

Robin Daugherty


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.

like image 44
AyushKatiyar Avatar answered Sep 22 '22 23:09

AyushKatiyar