npm throws EACCES error on installation of Angular CLI

后端 未结 9 553
没有蜡笔的小新
没有蜡笔的小新 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 16:01

    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.

    0 讨论(0)
  • 2020-12-11 16:04

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

    0 讨论(0)
  • 2020-12-11 16:10

    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
    
    0 讨论(0)
提交回复
热议问题