sh: 1: node: Permission denied
Solution 1
Got the same error sh: 1: node: Permission denied
So this worked for me
npm config set user 0
npm config set unsafe-perm true
Solution 2
These issues happen because of broken packages. Go to the main folder. If using Linux use command
sudo rm -rf node_modules.
After that run this command if you are using yarn
yarn install
If you are using npm run this command
npm install
Solution 3
in fact, npm can't use root account to install anything. if you use root account, npm will create a non-permission account to install. in this case, if the package need to execute writeFile or other operation which need permission, the error node: Permission denied will be raised.
so, you can choose optional arbitrary under:
- npm install xxx --unsafe-perm
- npm config set unsafe-perm true
- create high-permission account dedicate to execute
npm install
Solution 4
The /root/.npm/... log path in your original message shows you're already running as root, and (despite what others advise) I'd say this is most likely causing your problem.
My (limited) experience running Node as root is that most npm install runs get quite a long way, but then fail with some variation on the error you showed. The only reliable solution I've found is to not run Node or npm as root at all on Ubuntu. Just use a normal user account to download and unpack the Node installation.
At least one problem with running as root for me turned out to be because some dependency-of-a-dependency npm install script was calling setuid to switch to a less-privileged user. For some reason, it chose UID 500—which doesn't exist on Ubuntu—and consequently lost all its privileges. The 'Permission denied' errors were therefore because I was running as root; setuid doesn't work for a normal user.
I believe this is related to Error: setuid user id does not exist npm ERR! when npm install forever -g.
Solution 5
Delete the node_modules and install it again
sudo rm -rf node_modules
npm install
Related videos on Youtube
Comments
-
Fil 3 monthsTried to run this command on ubuntu 18.04
npm install -g pngquant-binbut I got this error,
[..................] | fetchMetadata: sill resolveWithNewModule [email protected] checking installable status npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5 /root/.nvm/versions/node/v10.8.0/bin/pngquant -> /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin/cli.js > [email protected] postinstall /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin > node lib/install.js sh: 1: node: Permission denied npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! [email protected] postinstall: `node lib/install.js` npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the [email protected] postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-08-12T18_08_02_197Z-debug.logDo you do you know how to deal with this? I tried every solution found in this articles yet not succeeded.
-
Jared Chu almost 4 yearsThis is the correct answer if you run NPM under root account. But please remember that it's unsafe (unless you know what're you doing).
-
jacobq over 3 yearsWow, I'm happy to find that this works, but also disappointed that the error message is so misleading. I ran into this usingnvmon a Raspberry Pi 3 (raspbian image from April 2019) and fought it for over an hour. Where might one make a PR to print out a warning like "Refusing to run with unsafe permissions (e.g. root user). See <URL> for more information."? -
Félix Adriyel Gagnon-Grenier over 3 yearsIf you know, could you expand on what is actually causing the permission problem? -
Rohan about 2 yearsYou are awesome maaan
-
Szymon Roziewski almost 2 yearsfor me doesnt help -
Amit Kumar Khare over 1 yearit worked for me, but is there a better way? -
Carlos Eduardo Olivieri over 1 yearWorked fine for me, great! Linux Debian Buster. Node v14.16.1 and NPM 6.14.12
-
bcbrian over 1 yearThis is probably a bad practice on a personal machine. That being said I use docker, WSL2, for dev environments and don't generate a user. this worked for my when trying to install story-book via
npx sb init -
Jesse de Wit over 1 yearNever use root permission when installing npm packages -
Admin 11 monthsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. -
Jakub Kurdziel 7 monthsBest way to delete node_modules is by using npkill just typenpx npkill