This article will tell you how to install node.js with nvm.

1.Install nvm

1.1 Install nvm with install script

The creators of nvm provide a simple script that automatically installs nvm:

cURL:

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

or Wget:

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

If it is installed successfully ,you use command nvm --version and you will see the version.

1.2 Set environment variable

After running the install script, if you get nvm: command not found ,you need to set the environment variable of nvm.

Add the following text to the end of ~/.bashrc

1
2
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Open Terminal ,and paste the text below to reload the environment variable.

1
$ source ~/.bashrc

2.Install Node.js

If nvm is installed, open terminal and run the following command to install Node.js:

1
$ nvm install stable

3.Reference

Node Version Manager