NVM & Node.js - Recommended install for all users

Solution 1:

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.

Solution 2:

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.