Search code examples
node.jsubuntunvm

Why is node not available to all users with NVM?


It's probably a newbie question but I'm wondering why when I install node with nvm, it is only available for this user (it's not "global").

Let's say I'm logged into the server with a user "admin":

curl https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh
source ~/.profile

nvm install 0.10.30
nvm use 0.10.30

node -v
# outputs v0.10.30

Node is up and running for this user but when I switch to the root:

su
node -v

It displays:

The program 'node' can be found in the following packages:
 * node
 * nodejs-legacy
Try: apt-get install <selected package>

Why is that? Is there a way to install node and make it available to all users? (I don't want to reinstall every time I need it for a new user.)


Solution

  • The problem is that NVM installs node.js to a user's local directory, and updates that user's .profile.

    Here's a one line script that can copy your install to /usr/local/bin, where everybody can use node.js:

    https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps

    n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local