Installing NPM and Node with NVM

Installing and upgrading Node and NPM can be a pain. More so if you need to manage multiple versions for different projects. Well not any more. use Node version manager

1. First make sure you have the right tools to allow you to build source packages

1
2
sudo apt-get update
sudo apt-get install build-essential libssl-dev

2. Download and install NVM

1
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

You can get the most uptodate version number from here.

3. Source your profile so you don’t need to restart your terminal

1
source ~/.profile

4. Versions

nvm ls lists installed versions
nvm ls-remote lists all available versions

1
2
3
4
5
6
7
8
9
v6.8.0
v6.8.1
v6.9.0 (LTS: Boron)
-> v6.9.1 (LTS: Boron)
v6.9.2 (LTS: Boron)
v6.9.3 (LTS: Boron)
v6.9.4 (Latest LTS: Boron)
v7.0.0
v7.1.0

5. Install

Pick the version you would like to install and run

1
nvm install 7.1.0

6. Activate the version you require

You have two options here. You can manually select a version

1
nvm use 7.1.0

or use a .nvmrc file

1
2
$ echo "7.1.0" > .nvmrc
$ echo "lts/*" > .nvmrc # to default to the latest LTS version

Then you can also nvm use without a version and it will respect the .nvmrc file

Setting a default is also a good idea so you can use NPM from any directory

1
nvm alias default 6.9.1

7. Removing old versions

1
nvm uninstall 6.9.1