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条回答
Lonely孤独者°
2楼-- · 2020-02-26 13:52

Steps to install angular cli.

  1. Download Nodejs and Install it. https://nodejs.org/en/
  2. Open terminal and type: sudo npm install -g @angular/cli

Just remember that -g represents global scope hence package is installing in root level folders. Hence the command should start with "sudo"

查看更多
别忘想泡老子
3楼-- · 2020-02-26 13:52

This worked for me.

 sudo npm install --unsafe-perm -g @angular/cli 
查看更多
祖国的老花朵
4楼-- · 2020-02-26 13:52

This seems like a problem with your node/npm and not with Angular CLI.

Please have a look at the fixing npm permissions page, common errors page, npm issue tracker, or open a new issue if the problem you are experiencing isn't known.

查看更多
孤傲高冷的网名
5楼-- · 2020-02-26 14:02

After several tries, I finally installed angular-cli successfully via nvm. In detail:

Install nvm:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
export NVM_DIR="/Users/mkotsollaris/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm --version
0.33.0

Then install node through nvm:

nvm install stable
nvm install node

Thereafter, install angular-cli:

npm install -g @angular/cli
mkotsolarissMBP:myapp mkotsollaris$ ng -v

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 1.6.5
Node: 9.4.0
OS: darwin x64
Angular: 5.2.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.5
@angular-devkit/build-optimizer: 0.0.41
@angular-devkit/core: 0.0.28
@angular-devkit/schematics: 0.0.51
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.5
@schematics/angular: 0.1.16
typescript: 2.5.3
webpack: 3.10.0
mkotsolarissMBP:myapp mkotsollaris$ 

Verify that ng works properly:

ng new my-project
cd my-project
ng serve

The app will start on localhost:4200.

enter image description here

查看更多
我只想做你的唯一
6楼-- · 2020-02-26 14:03

These are the codes I used

sudo npm uninstall -g angular-cli
sudo npm uninstall -g @angular/cli
sudo npm cache clean --force
npm install -g @angular/cli
alias ng="~/node_modules/@angular/cli/bin/ng"

for check

ng --version
查看更多
登录 后发表回答