npm throws EACCES error on installation of Angular CLI

后端 未结 9 552
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 15:34

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         


        
相关标签:
9条回答
  • 2020-12-11 15:46

    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.

    0 讨论(0)
  • 2020-12-11 15:46

    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

    0 讨论(0)
  • 2020-12-11 15:48

    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!

    0 讨论(0)
  • 2020-12-11 15:54
    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 and add this line:

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

    4. update your system variables:

      source ~/.profile

    Reference: Resolving EACCES permissions errors when installing packages globally

    0 讨论(0)
  • 2020-12-11 15:55

    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.

    0 讨论(0)
  • 2020-12-11 15:56

    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

    0 讨论(0)
提交回复
热议问题