Aller au contenu principal
Version: 3.0.0

How to install Node.js environment

Use scenario

Generally, you can download the corresponding installation package from the Node.js official website to complete the environment configuration.

However, when you develop on-premises, you often need to quickly update or switch the version.

The community has solutions such as nvm, n, etc. We recommend cross-platform [nvs](https:/ /

  • nvs is cross-platform.
  • Nvs is written based on Node, and we can participate in maintenance.

Friendly reminder: both Node 6.x and 8.x will end LTS support this year. please upgrade to 10.x as soon as possible.

PS:nvs is generally only used for local development. For more information, see Popular text: What should I do if O & M does not upgrade the Node version?

How to install

Linux / macOS environment

The project corresponding to Git Clone can be used.

$ export NVS_HOME="$HOME/.nvs"
$ git clone --depth=1 "$NVS_HOME"
$ . "$NVS_HOME/" install

Windows environment

Due to the complexity of Windows environment configuration, it is recommended to use msi file to complete initialization. Visit nvs/releases to download the latest version of nvs.msi, and then double-click to install.

Configure mirror address

In China, due to reasons that everyone knows, it is necessary to modify the corresponding mirror address:

$ nvs remote node
$ nvs remote
default node

Guidelines for Use

With the following command, you can easily install the latest LTS version of Node.js.

# Install the latest LTS version
$ nvs add lts
# Configure as default version
$ nvs link lts

Install other versions:

# Install other versions and try them
$ nvs add 12
# View installed versions
$ nvs ls
# Switch version at current Shell
$ nvs use 12

For more information, see nvs --help.

Common npm global module

If you use nvs, the default prefix is the installation path of the currently activated Node.js version. One problem is that after switching versions, the previous installation of the global command module needs to be reinstalled, which is very inconvenient. The solution is to configure a unified global module installation path to ~/.npm-global, as follows:

$ mkdir -p ~/.npm-global
$ npm config set prefix ~/.npm-global

You must also configure environment variables in the ~/.bashrc or ~/.zshrc file:

$ echo "export PATH=~/.npm-global/bin:$PATH" >> ~/.zshrc
$ source ~/.zshrc