How to use nvm?
nvm
is short for Node Version Manager, it can be used to manage multiple Node.js versions installed on a host.
Install
Please refer to its official repo on Github for installation.
Usage
List versions
$ nvm ls
-> system
node -> stable (-> N/A) (default)
iojs -> N/A (default)
After nvm
is newly installed, there is only one version referenced by system
. It is referred to the currently install Node.js on this host, which is not managed by nvm
.
Install current (latest) version
$ nvm install node
Downloading and installing node v10.4.1...
Downloading https://nodejs.org/dist/v10.4.1/node-v10.4.1-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.4.1 (npm v6.1.0)
Creating default alias: default -> node (-> v10.4.1)
$ nvm ls
-> v10.4.1
system
default -> node (-> v10.4.1)
node -> stable (-> v10.4.1) (default)
stable -> 10.4 (-> v10.4.1) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.3 (-> N/A)
lts/carbon -> v8.11.3 (-> N/A)
Install current LTS version
$ nvm install lts/*
Downloading and installing node v8.11.3...
Downloading https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.11.3 (npm v5.6.0)
$ nvm ls
-> v8.11.3
v10.4.1
system
default -> node (-> v10.4.1)
node -> stable (-> v10.4.1) (default)
stable -> 10.4 (-> v10.4.1) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.3 (-> N/A)
lts/carbon -> v8.11.3
Modify the default version
As you can see above, currently, the default version points to the latest Node.js version. If you want to change it to current LTS version, run command below:
$ nvm alias default lts/*
Switch between versions
$ nvm current
v8.11.3
$ nvm use default
Now using node v8.11.3 (npm v5.6.0)
$ nvm use node
Now using node v10.4.1 (npm v6.1.0)
For the complete usage, please run nvm
(without out any arguments) on command line.