topaxi.codes

How to install Node.js on Linux using NVM

In this post, we're going to install Node.js using the Node Version Manager bash script.

One benefit using nvm over a package repository is, that you won't need root access to install Node.js.
This method should probably not be used for your production server, but can be very helpful on your development and testing machines.

You can install nvm using a simple wget command:

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.1/install.sh | bash

After the install script completed, the script will append its executable path to your .bashrc (or depending on your shell a different) file. Before you can use nvm source your .profile file.

$ source ~/.profile

If you don't want to execute arbitrary shell scripts from the internet you can follow the nvm readme on the Github repository: creationix/nvm/README

Once installed, simply type nvm install node in your shell and the latest Node.js version will be installed on your system.

The Node Version Manager also enables you to quickly install and switch between different Node.js versions. This allows you to test your applications for older versions of each platform.

Example:

$ nvm install v0.10 # to install the latest of the old Node.js 0.10 branch

nvm will automatically switch to the installed version, to switch back to the latest stable version simply type:

$ nvm use node

To preserve global npm packages when installing a new version of node use the following command:

$ nvm install node --reinstall-packages-from=default

That's it for now. Enjoy!