Can't install angular-cli on Mac

2020-02-26 13:18发布

This is probably very trivial, but I am hitting my head against the wall while I am trying to (unsuccessfully) install angular-cli.

I am following the official angular-cli documentation here.

mkotsollariss-MacBook-Pro:~ mkotsollaris$ npm -v
5.6.0
mkotsollariss-MacBook-Pro:~ mkotsollaris$ node -v
v8.9.4

Then I run npm install -g angular-cli which gives me:

mkotsollariss-MacBook-Pro:~ mkotsollaris$ npm install -g angular-cli
npm WARN deprecated angular-cli@1.0.0-beta.28.3: angular-cli has been renamed to @angular/cli. Please update your dependencies.
npm WARN deprecated gulp-util@3.0.7: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN @angular/core@2.4.10 requires a peer of rxjs@^5.0.1 but none is installed. You must install peer dependencies yourself.
npm ERR! path /Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir
npm ERR! Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular'
npm ERR!  { Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular'
npm ERR!   stack: 'Error: EACCES: permission denied, rmdir \'/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rmdir',
npm ERR!   path: '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mkotsollaris/.npm/_logs/2018-01-14T23_11_22_610Z-debug.log
mkotsollariss-MacBook-Pro:~ mkotsollaris$ ng
-bash: ng: command not found

I think I have tried almost everything on the web, and still can't make this to work.

My OS is MacOS High Sierra 10.13.2.

Any idea what am I missing here?

11条回答
走好不送
2楼-- · 2020-02-26 13:39

After going back and forth i used homebrew. Just run: "sudo brew install angular-cli" If you have homebrew installed, it solved all my problems including node-sass issues on angular 7

查看更多
孤傲高冷的网名
3楼-- · 2020-02-26 13:41

To get rid of access errors, these steps can help:

Step1: Homebrew installation[https://brew.sh/]: (on terminal)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Step2: brew install node

Check version: node -v, npm -v

Step3: brew install -g angular-cli

Check version: ng --version

Step4: ng new First-App

查看更多
家丑人穷心不美
4楼-- · 2020-02-26 13:43

i faced similar issue while installing angular-cli on Mac Mojave.

Correct installation steps are:

  1. Install npm using package manager.
  2. above step sets the directory owner of /usr/local/lib/node_modules/ to root.
  3. execute below command to set the owner to your user:
    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

  4. npm install -g @angular/cli (avoid using sudo)

查看更多
一夜七次
5楼-- · 2020-02-26 13:43

Error: EACCES: permission denied, rmdir '/Users/mkotsollaris/.npm-packages/lib/node_modules/.staging/@angular' you do not have permissions to access the directories node_modules.

your process want to make changes to your directories and it is not allowed to access you can easily be in super user (admin), have access permission is thrown the command so that the processur can modify the node_modules angular.

sudo npm install -g @angular/cli

查看更多
做个烂人
6楼-- · 2020-02-26 13:49

Try this:

sudo npm install -g @angular/cli 
查看更多
太酷不给撩
7楼-- · 2020-02-26 13:51

I've faced a problem very similar to this one before. It's most likely that you installed Node & NPM as root etc.

You should attempt to re-install Node & NPM without sudo, one of these scripts might work for you: https://gist.github.com/isaacs/579814

Then retry npm i -g angular-cli and hopefully should work no problems.

Best of luck!

查看更多
登录 后发表回答