Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does node is 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 log 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 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.)

like image 458
Julien Le Coupanec Avatar asked Aug 18 '14 17:08

Julien Le Coupanec


People also ask

Does NVM require admin rights?

To use NVM, you need to open PowerShell or Command Prompt as an admin. You can also use Git bash. To open PowerShell as admin, right-click on Start and select “PowerShell (Admin)”. To open Command Prompt as admin, search for “cmd” and select “Open as Administrator” on the right.

How install npm for all users?

Open an administrator level command prompt. Note the current global prefix: npm prefix -g. Set the global prefix to the CI user: npm config set prefix <C:\Users\CI_USER\AppData\Roaming\npm> Install the needed packages: npm i -g PKG.

Do I need Node for NVM?

Before installing NVM, you do not need a Node version installed on your machine, and, if you do have Node installed, it does not matter. Installing NVM and using it to install Node versions will work separately from the existing one. However, since we are not installing Node directly, we'll focus on using NVM.


1 Answers

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
like image 188
FoggyDay Avatar answered Sep 28 '22 21:09

FoggyDay