8

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 [email protected]: angular-cli has been renamed to @angular/cli. Please update your dependencies.
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN @angular/[email protected] 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?

4
  • 2
    Please try running this command again as root/Administrator. Did you try using sudo? Jan 14, 2018 at 23:44
  • @VSG24 Not necessary, nor constructive. Flagged.
    – Phix
    Jan 15, 2018 at 0:47
  • @SterlingArcher Running with sudo gives me "Warning "root" does not have permission to access the dev dir" which leads me to this which does not solve the issue... Jan 15, 2018 at 7:50
  • Angular CLI GitHub page is the best resource for how to install the CLI. The link you are using is instructing you to install a version of the CLI that is no longer supported; hasn't been for many months. Jan 15, 2018 at 12:05

14 Answers 14

26

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
  • This worked. Before using this method, the installed failed at the python library section.
    – DFBerry
    Apr 17, 2018 at 12:00
  • Menelaos Kotsollaris - great answer. Thank you Aug 18, 2018 at 9:10
  • Just curious... why did only installing through nvm work? :(
    – aashah7
    Jan 19, 2019 at 5:24
  • A very minor correction: use 'ng version' in Angular CLI: 7.2.3. Just 'ng -v' now yields the list of available commands (including version :) Jan 23, 2019 at 20:34
  • Can anyone explain why using nvm worked while using sudo npm install -g @angular/cli and linking did not work?
    – pixel
    Oct 2, 2019 at 19:14
24

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)

1
  • 1
    Thanks, this was useful
    – Kevin
    Nov 7, 2019 at 22:23
13

Try this:

sudo npm install -g @angular/cli 
1
6

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

0
2

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

1

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

1

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
1

I tried all of the solutions mentioned here but none of them worked for me. After searching for solutions for hours I finally found one simple solution

  1. Install brew by /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. brew install angular-cli
  3. ng version

That's all you have successfully installed angular-cli on your mac !!!

0

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!

1
  • thanks but that didn't work for me; I ended up installing @angular/cli through nvm. Jan 23, 2018 at 18:36
0

This worked for me.

 sudo npm install --unsafe-perm -g @angular/cli 
0

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.

0

Please see docs on how to resolve this issue: Resolving EACCES permissions errors when installing packages globally

That said, it worked for me when I run this:

sudo npm install -g @angular/cli
0

For my mac environment

sudo chown -R $USER /usr/local/lib/node_modules

running this solve the issue after that just run npm command

0

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"

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.