19

I'm deploying an Angular project on Ububtu 16.04 and get these errors when I run sudo npm install. (won't work without sudo). It seems that npm doesn't have permission to install. I recently updated to nodejs to 8.11.4 and still have the same error so it wasn't a version problem apparently. How can I give it the correct permissions?

gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir '/var/www/project_name/node_modules/node-sass/build' gyp ERR! System Linux 4.4.0-1065-aws gyp ERR! command "/usr/local/bin/node" "/var/www/project_name/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "-libsass_library=" gyp ERR! cwd /var/www/front-stormsensor/node_modules/node-sass gyp ERR! node -v v8.11.4 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok Build failed with error code: 1 

Is there something off within my project? Or an incorrect installation? Not sure where to go from here, thank you

2
  • Try running the command with sudo. sudo npm install for eg/ Commented Sep 8, 2018 at 1:52
  • 1
    Make sure you're logged in as an admin user on the server. Normally www-user or similar. Also check owner of the folder, might need to change it first Commented Sep 8, 2018 at 9:54

9 Answers 9

73

try the following command

sudo npm i --unsafe-perm 

if it doesn't work try the following

sudo rm -rf ~/.node-gyp sudo npm cache clean -f sudo npm install -g n sudo n stable sudo npm i --unsafe-perm 
Sign up to request clarification or add additional context in comments.

1 Comment

man I love you! been fighting with this issue for 2 days .. thanks!
9

I fixed it by run this command.

sudo npm i --unsafe-perm

Comments

8

In case you're installing something globally, you can use:

$ sudo npm install -g <package> --unsafe-perm 

Comments

8

use following command to install

sudo npm install --unsafe-perm=true --allow-root

Comments

3

This solution from jnambiar worked for me. My OS is OSX 10.11.6. It's basically permissions issue.

sudo rm -rf ~/.node-gyp sudo npm cache clean -f sudo npm install -g n sudo n stable sudo npm i --unsafe-perm 

Above set of commands helped me resolve the issue. I am posting this to approve the set of commands which worked for me while I struggled to install the node-sass package for 2 days.

1 Comment

This was the key to ending several hours of toil.
1

For anyone that might still have this problem, I solved it by following the suggestion of the second comment above and logging in as the root user on my ubuntu instance, as described in the second answer on this question here.. That allowed me to npm install without errors.

Comments

1

This command worked for me on windows.. sudo npm install --unsafe-perm

Comments

1

I used yarn instead of npm and it worked

Comments

0

npm permissions are quite a headache. The above solutions didn't work on my machine. Yarn did the trick. sudo npm i yarn -g yarn add

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.