25

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
Itchydon
  • 2,572
  • 6
  • 19
  • 33
calibre24
  • 359
  • 1
  • 3
  • 7
  • 1
    you are trying to install a module globally, in order to do that you need to do it with higher privileges, run `npm install -g angular-cli` as the `root` user - `sudo npm install -g angular-cli` – mic4ael Feb 04 '17 at 15:52
  • 1
    For those who get the same error, and those who copied a repo with .node folder in it! remove .node folder before installing! – Diana Jan 24 '22 at 11:27
  • I have removed the node modules folder and tried npm install. It worked. Thanks Diana. – Srikanth Reddy Jun 23 '22 at 05:21

12 Answers12

35

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.

Robin Daugherty
  • 7,115
  • 4
  • 45
  • 59
  • 2
    This was a great answer. Following the steps provided in the npm documentation link, I was able to solve the problem. (I removed an existing node, and reinstalled it through nvm as it was recommended) –  Aug 19 '20 at 00:29
23

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.

ysf
  • 4,634
  • 3
  • 27
  • 29
AyushKatiyar
  • 1,000
  • 8
  • 15
7
  1. create a directory for global installations:

    mkdir ~/.npm-global

  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'

  3. create a ~/.profile file

  4. add this line to your new ~/.profile file:

    export PATH=~/.npm-global/bin:$PATH

  5. update your system variables:

    source ~/.profile

Reference: Resolving EACCES permissions errors when installing packages globally

Tony Brasunas
  • 4,012
  • 3
  • 39
  • 51
leo valeriano
  • 810
  • 8
  • 8
6

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

arthur.sw
  • 11,052
  • 9
  • 47
  • 104
Mateus Galasso
  • 320
  • 1
  • 5
  • 14
  • 1
    Thank goodness. Other fixes didn't help me, so I guess it had to be changing ownership of the whole usr/local directory. Anyway. You legend! – Joel Balmer Jan 17 '19 at 16:38
  • 2
    that is a really bad idea. You shouldn't change the ownership of /bin /share – Tarick Welling Jun 17 '19 at 09:10
  • This wrecked my system (no access to sudo or su anymore), **do not use this**!! To revert, I had to login to a recovery shell and issue "sudo chown -R root /usr/{lib/node_modules,bin,share}". – ciri Aug 26 '21 at 15:23
3

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.

kemparaj565
  • 379
  • 3
  • 6
1

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!

1

I had this problem on Linux, where the repository was on a partition that was mounted with option noexec. Remounting the partition with exec solved it for me.

I had installed node through nvm, which is the recommended way to avoid permission issues. But if nvm can't execute in your folder, it won't work in some cases.

Jesse de Wit
  • 3,867
  • 1
  • 20
  • 41
0

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. :)

raikumardipak
  • 1,461
  • 2
  • 29
  • 49
0

Use:

sudo npm install -g @angular/cli

Then it will work, mine was also not working, but it worked with sudo.

Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29
FRXGFA
  • 9
  • 3
-1

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
cramopy
  • 3,459
  • 6
  • 28
  • 42
-1

EACCES: permission denied, symlink '../lib/nod code example Example 1: Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

sudo npm install -g nodemon //easiest fix

Example 2: npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/bin/ng' sudo npm install -g @angular/cli sudo chown -R $USER /usr/local/lib/node_modules

  • 1
    Please format your answer and clarify it, it is very unclear as the text is all together and it is not clear if this is an actual answer or you have an error. – Ruli Nov 09 '21 at 07:30
-1

**

Don't worry!!

** Just use command form Root user like Ex -

  1. developer@developer:~$ sudo su
  2. root@developer:/# npm install -g @angular/cli@11

And All Set

vikas thakur
  • 132
  • 1
  • 4