I'm trying to install globally some packages for my Unix environment on Windows with WSL. I use nvm
to manage the different versions of Node.js.
The problem is while using the sudo
command before a global npm install :
sudo npm install --global prompt-pure
I get an error: sudo: npm: command not found
!
Doing a simple npm install --global pure-prompt
will work, but as I'm not super user, the global installation ends up with a permission error.
How can I fix this annoying problem and keep nvm
?
Thanks by advance
When you try to run sudo npm
, it tries to run the npm binary file /usr/bin/npm
but your binary is located in a different place, which can be found running which npm
.
Example: /home/damo/.nvm/versions/node/v8.11.1/bin/npm
The solution is to create a link in /usr/bin/
pointing to the actual binary:
sudo ln -s "$(which npm)" /usr/bin/npm
You can also add the following link so you can run sudo node
sudo ln -s "$(which node)" /usr/bin/node