Reputation: 366
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
Upvotes: 5
Views: 10540
Reputation: 126
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
Upvotes: 9
Reputation: 1118
For me I needed to actually cheat and run as root
before installing node as root
. For this I ran sudo su
in a Ubuntu WSL term and then installed node.
Once I did that I could sudo su
then npm run special-script
.
I don't know a better way to get a script to attach to restricted ports like 443 for testing https connections but it works.
Upvotes: 1
Reputation: 6443
As you will find in the man file for sudo man sudo
sudo will execute a command as another user. That other user has a different home directory to you and access to different commands
When i run sudo which node
i get nothing, but which node
returns /home/damo/.nvm/versions/node/v8.11.1/bin/node
Lets look at your actual goal. You say you are trying to install pure-prompt, i know this does not ask your explicit question but given you have zsh installed have you tried oh-my-zsh (https://github.com/robbyrussell/oh-my-zsh) i use this on every install of linux i ever have to work with (VMs, WSL, docker). Very customizable and looks great out of the box.
Upvotes: 0