First, use the following command to install the NVM
$ curl-o-https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | Bash
When the download and installation is complete, the user exits the login or source the environment variable again.
$ . ~/.bashrc
View current system node version
$ NVM ls
n/a
node-> stable (-> N/a) (default)
Iojs-> N/A (default)
You can see that no version of node is currently installed in the system
Install the specified version of node using "NVM Install"
$ NVM Install v6.10.0
Downloading and installing node v6.10.0 ...
Downloading https://nodejs.org/dist/v6.10.0/node-v6.10.0-linux-x64.tar.gz
... ######################################################################## 100.0%
Computing checksum with Sha256sum
checksums matched!
Now using node v6.10.0 (NPM v3.10.10)
Creating default Alias:default-> v6.10.0
$ nvm install v7.10.0
down Loading and installing node v7.10.0
... Downloading https://nodejs.org/dist/v7.10.0/node-v7.10.0-linux-x64.tar.gz
... ######################################################################## 100.0%
Computing checksum with Sha256sum
checksums matched!
Now using node v7.10.0 (NPM v4.2.0)
View node version information again
$ NVM List
v6.10.0
-> v7.10.0
default-> v6.10.0
node-> stable (-> v7.10.0) (default) C5/>stable-> 7.10 (-> v7.10.0) (default)
Iojs-> N/A (default)
lts/*->-Lts/boron (->/n) lts
/argon-> v4.8.3 (-> N/a)
Lts/boron->-v6.10.3 (-> N/a)
There are now two versions of node, where "-> v7.10.0" describes the v7.10.0 version currently in use.
$ node-v
v7.10.0
$ nvm current
v7.10.0
You can now switch the node version using NVM use, such as:
$ NVM Use v6.10.0 now
using node v6.10.0 (NPM v3.10.10)
After switching, view the node version information "-> v6.10.0" to describe the v6.10.0 version currently in use.
$ NVM List
-> v6.10.0
v7.10.0
default-> v6.10.0
node-> stable (-> v7.10.0) (default) C5/>stable-> 7.10 (-> v7.10.0) (default)
Iojs-> N/A (default)
lts/*->-Lts/boron (->/n) lts
/argon-> v4.8.3 (-> N/a)
Lts/boron->-v6.10.3 (-> N/a)
$ node-v
v6.10.0
$ nvm current
v6.10.0
Finally, if you want to set the default node version of the system user, you can use NVM alias default to set it.
$ NVM alias default v7.10.0
default-> v7.10.0
$ nvm ls
-> v6.10.0
v7.10.0
Default -> v7.10.0
Node-> stable (-> v7.10.0) (default)
stable-> 7.10 (-> v7.10.0) (default)
Iojs -> N/A (default)
lts/*-> Lts/boron (-> N/a)
Lts/argon-> v4.8.3 (-> N/a)
Lts/boron-> V 6.10.3 (-> N/a)