Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NVM & Node.js - Recommended install for all users

Tags:

node.js

nvm

is there a recommended install for nvm so all users can use it? i cannot find anything on the web regarding this.

this is what i did

  • installed nvm in a common directory
  • put the nvm.sh script locationin .profile for all users
  • created a nvm/alias directory (nvm complains if this is not here for other users)

then each user must either run "nvm use " or put it in their profile by default

not sure if there is a better way?

thanks

like image 369
jadent Avatar asked Jul 18 '12 13:07

jadent


People also ask

What is NVM used for?

Introducing nvm nvm stands for Node Version Manager. As the name suggests, it helps you manage and switch between different Node versions with ease. It provides a command-line interface where you can install different versions with a single command, set a default, switch between them and much more.

Can we install NVM on windows?

Node Version Manager, more commonly called nvm, is the most popular way to install multiple versions of Node. js, but is only available for Mac/Linux and not supported on Windows. Instead, we recommend installing nvm-windows and then using it to install Node. js and Node Package Manager (npm).

Should I use NVM to install node?

Note: We do not recommend using nvm to install Node. js for production environments. If you're installing Node. js on your production environment you should consider using your OS's package manager, or your server tooling of choice, to install and lock the environment to a specific version of Node.


4 Answers

Here is what I did:

  1. Installed nvm in /opt/nvm as root. Seemed like an appropriate location.

    # git clone [email protected]:creationix/nvm.git /opt/nvm
    
  2. Created the directory /usr/local/nvm. This is where the downloads will go ($NVM_DIR)

    # mkdir /usr/local/nvm
    
  3. Create the directory /usr/local/node. This is where the NPM global stuff will go:

    # mkdir /usr/local/node
    
  4. Created a file called nvm.sh in /etc/profile.d with the following contents:

    export NVM_DIR=/usr/local/nvm
    source /opt/nvm/nvm.sh
    
    export NPM_CONFIG_PREFIX=/usr/local/node
    export PATH="/usr/local/node/bin:$PATH"
    
  5. Re-login to a shell session, then set the default node version.

    # nvm install 0.10
    # nvm alias default 0.10
    

The node binaries should now be in the PATH for all users the next time you login to a shell session. NPM will install global things to the /usr/local/node prefix.

like image 98
Tim Smart Avatar answered Oct 16 '22 05:10

Tim Smart


It's best to install one copy of node globally so that other users can access it. To do this, run the following command (entering your user's password at the prompt):

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

This commend is copying whatever version of node you have active via nvm into the /usr/local/ directory and setting the permissions so that all users can access them.

To check that it works, become the root user and do another which command to make sure that node is now installed to /usr/local/bin:

sudo -s
which node

If you ever want to change the version of node that's installed system wide, just do another nvm use vXX.XX.XX to switch your user's node to the version you want, and then re-run the first command above to copy it to the system directory.

like image 29
Glowin Avatar answered Oct 16 '22 06:10

Glowin


  1. Login as root: sudo -s
  2. Install nvm: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | NVM_DIR=/usr/local/nvm bash
  3. Created a file called nvm.sh in /etc/profile.d with the following contents: #!/usr/bin/env bash export NVM_DIR="/usr/local/nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  4. Run /etc/profile.d/nvm.sh
  5. Install node: nvm install node
  6. Optionally update npm with: npm install -g npm
like image 24
Biscar Avatar answered Oct 16 '22 06:10

Biscar


Install NVM on your Linux server, after that install node version using NVM (run all the command as root user). After that run the below command for all the users get nodejs available with nvm

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

The above command is a bit complicated, but all it’s doing is copying whatever version of node you have active via nvm into the /usr/local/ directory (where user installed global files should live on a linux VPS/server) and setting the permissions so that all users can access them.

/root/.nvm/versions/node/v8.10.0/bin/node

Switch the user name check your node version.

su - username
which node
/usr/local/bin/node
like image 8
bibincatchme Avatar answered Oct 16 '22 07:10

bibincatchme