nvm: `npm install -g` responds with "node: Permission denied"

  • Operating system and version: ubuntu 16.04

  • nvm debug output:

root@ubuntu:~# nvm debug
nvm --version: v0.33.0
$SHELL: /bin/bash
$HOME: /root
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v6.10.0
which node: $NVM_DIR/versions/node/v6.10.0/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v6.10.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v6.10.0
npm root -g: $NVM_DIR/versions/node/v6.10.0/lib/node_modules
  • nvm ls output:
root@ubuntu:~# nvm ls
         v6.9.5
->      v6.10.0
default -> 6 (-> v6.10.0)
node -> stable (-> v6.10.0) (default)
stable -> 6.10 (-> v6.10.0) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> v6.10.0)
lts/argon -> v4.8.0 (-> N/A)
lts/boron -> v6.10.0
  • How did you install nvm? (e.g. install script in readme, homebrew): curl script from readme

  • What steps did you perform? npm i -g testcafe

  • What happened?

root@ubuntu:~# npm i -g testcafe
/root/.nvm/versions/node/v6.10.0/bin/testcafe -> /root/.nvm/versions/node/v6.10.0/lib/node_modules/testcafe/bin/testcafe.js

> testcafe-browser-tools@1.2.0 postinstall /root/.nvm/versions/node/v6.10.0/lib/node_modules/testcafe/node_modules/testcafe-browser-tools
> node ./bin/fix-permissions.js

sh: 1: node: Permission denied
/root/.nvm/versions/node/v6.10.0/lib
└── (empty)

npm ERR! Linux 4.9.7-x86_64-linode80
npm ERR! argv "/root/.nvm/versions/node/v6.10.0/bin/node" "/root/.nvm/versions/node/v6.10.0/bin/npm" "i" "-g" "testcafe"
npm ERR! node v6.10.0
npm ERR! npm  v3.10.10
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn

npm ERR! testcafe-browser-tools@1.2.0 postinstall: `node ./bin/fix-permissions.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the testcafe-browser-tools@1.2.0 postinstall script 'node ./bin/fix-permissions.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the testcafe-browser-tools package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/fix-permissions.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs testcafe-browser-tools
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls testcafe-browser-tools
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/npm-debug.log
npm ERR! code 1
  • What did you expect to happen? installation of testcafe globally

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH? Not that I see.

  • If you are having installation issues, or getting “N/A”, what does curl -v nodejs.org/dist/ print out?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 24 (9 by maintainers)

Most upvoted comments

You can run this as root

npm config set user 0 npm config set unsafe-perm true npm install -g package

source

Had this issue when trying to set up a Dockerfile to handle my dependencies.

https://github.com/creationix/nvm/issues/1407#issuecomment-316858947 fixed it for me as well. I ended up creating my Dockerfile like this:

Dockerfile:

RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
ADD setup_nvm.sh setup_nvm.sh
RUN sh ./setup_nvm.sh

setup_nvm.sh

#!/usr/bin/env sh

export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

nvm install node
npm config set user 0
npm config set unsafe-perm true
npm install -g npm
npm install package

sudo find ~/.nvm/ -type d -user root -exec sudo chown -R $USER: {} +

Works here

npm config set user 0
npm config set unsafe-perm true

Works.

unsafe-perm is unsafe tho; you shouldn’t need sudo or unsafe perms to do anything with node/npm.

@gregoryderner’s solution is the only one that worked for me here. Running on WSL2 Ubuntu 20.04

Let’s call this one fixed! 😃

I followed the instructions here to create a sudo user (called it worker1): https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Then reinstalled nvm in that account. Then:

worker1@ubuntu:~$ npm install testcafe

> testcafe-browser-tools@1.2.0 postinstall /home/worker1/node_modules/testcafe-browser-tools
> node ./bin/fix-permissions.js

File permissions fixed
/home/worker1
└─┬ testcafe@0.13.0
. . .

I don’t fully understand the ramifications of using a non-root user, but it’s enough to nod my head, cheer, and move along 😃 Thanks for your help working through this; muchly appreciated kind sir! 👍 May others find this useful as well.