angular-cli: Error while installing @angular/cli on AWS Ubuntu 16.04 server

Bug Report or Feature Request (mark with an x)

- [ X] bug report -> please search issues before submitting
- [ ] feature request

Versions.

node v8.1.2 npm 5.0.3

Repro steps.

Setup new AWS Ubuntu Server: Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-d15a75c7

Then run commands below

sudo apt-get update

sudo apt-get install python -y

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential

sudo npm install node-gyp -g
sudo npm install -g @angular/cli

The log given by the failure.

ubuntu@ip-172-31-5-23:~$ sudo npm install -g @angular/cli
/usr/bin/ng -> /usr/lib/node_modules/@angular/cli/bin/ng

> node-sass@4.5.3 install /usr/lib/node_modules/@angular/cli/node_modules/node-sass
> node scripts/install.js

Unable to save binary /usr/lib/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/@angular/cli/node_modules/node-sass/vendor'
    at Object.fs.mkdirSync (fs.js:890:18)
    at sync (/usr/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/usr/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/usr/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:111:11)
    at Object.<anonymous> (/usr/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:154:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/usr/lib/node_modules/@angular/cli/node_modules/node-sass/vendor' }

> fsevents@1.1.2 install /usr/lib/node_modules/@angular/cli/node_modules/fsevents
> node install


> node-sass@4.5.3 postinstall /usr/lib/node_modules/@angular/cli/node_modules/node-sass
> node scripts/build.js

Building: /usr/bin/nodejs /usr/lib/node_modules/@angular/cli/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ '/usr/bin/nodejs',
gyp verb cli   '/usr/lib/node_modules/@angular/cli/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library=' ]
gyp info using node-gyp@3.6.2
gyp info using node@8.1.2 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import platform; print(platform.python_version());"` returned: "2.7.12\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.1.2
gyp verb command install [ '8.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.1.2
gyp verb ensuring nodedir is created /home/ubuntu/.node-gyp/8.1.2
gyp WARN EACCES user "root" does not have permission to access the dev dir "/home/ubuntu/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.1.2
gyp verb ensuring nodedir is created /usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.1.2
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.1.2
gyp verb ensuring nodedir is created /usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.1.2
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
gyp verb tmpdir == cwd automatically will remove dev files after to save disk space
gyp verb command install [ '8.1.2' ]
gyp verb install input version string "8.1.2"
gyp verb install installing version: 8.1.2
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 8.1.2
gyp verb ensuring nodedir is created /usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.1.2
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"

Desired functionality.

Use case is automating deployment to AWS. Would like to understand steps to avoid this error or for a fix.

Mention any other details that might be useful.

The error keeps repeating. Breaking out the error using Ctrl +C, and then reinstalling using: sudo npm install -g @angular/cli seems to work.

I can then run ng new myproject, run npm install, and ng serve.
The problem seems to be this initial error which goes in a loop.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

This seems to be a problem with installing https://github.com/sass/node-sass, which is one of the dependencies.

The problem most likely arises from the use of sudo, which is heavily discouraged while installing packages. Check out https://docs.npmjs.com/getting-started/fixing-npm-permissions to see how you can fix your permissions.

Per the npm video, I chose option 2. I use a different directory for npm globals. This works without any issues for me.

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.profile
source ~/.profile
npm i -g @angular/cli

Use this command sudo npm install -g @angular/cli@latest --unsafe-perm

@Martin-Wegner , thank u (y). I managed to install it using the first two steps you mentionned as root. I have to mention that the second step sudo npm i -g @angular/cli took me to an infinite loop like in #1734. So i bypassed it using @totomz 's answer on the same issue e.g sudo npm i -g --unsafe-perm @angular/cli. And : yes, the script is not good at all !!

@FaroukMohameden the Angular CLI npm install script is not very good… The problem is, that the installer script wants to put the symbolic link ng to /usr/bin/ so you need sudo… But with sudo you cannot install it because…the installer script is not very good 😉 But don’t worry, you can install it this way:

1.) Fix the permissions by changing the ownership and group of /usr/lib/node_modules/ to your user account: sudo chown -r XXX /usr/lib/node_modules/ and sudo chgrp -r XXX /usr/lib/node_modules/ 2.) sudo npm i -g @angular/cli 3.) sudo rm -fr /usr/lib/node_modules/@angular/cli/ 4.) sudo chown -r XXX /usr/lib/node_modules/@angular/ 5.) sudo chgrp -r XXX /usr/lib/node_modules/@angular/ 6.) npm i -g @angular/cli

Yes this solved the problem. thank you!

If this doesn’t work sudo npm install -g @angular/cli@latest --unsafe-perm surely this will work 😃 sudo chown -R root:root /usr/lib/node_modules/@angular/ and then sudo npm install -g @angular/cli@latest

Fixing the permissions as said here did not fix the problem for me.