nvm install and manage multiple versions of Node.js

Get the latest version of Node.js from the official website

The easiest way to install Node.js is to obtain the latest version of the installation file from the official website of Node.js to install it.

Insert picture description here

Windows system or MacOS system can refer to the following graphic tutorials to install:

The things to note here are:

  • For installation in this way, every time you update the version of Node.js, you need to download it from the official website and perform an overwrite installation.
  • In this way, only one version of Node.js can exist in the system, which is not suitable for comparative learning.

If you are contacting Node.js for the first time, it is recommended to install the latest version of Node.js using the official method first.

Use nvm to manage multiple versions of Node.js

First, let's take a brief look at nvm.

nvm is a software that manages multiple versions of Node.js through commands in a MacOS system developed by Tim Caswell .

For an introduction to nvm software, you can visit the github homepage of the project .

1. Install nvm version manager

To successfully install nvm, you must first install the Xcode software under the MaOS system. The Xcode software is about 4.3GB.

If you don't want to install Xcode software, but want to successfully install nvm, you can do as follows:

1. Open the "Terminal" window and enter the following commands.

xcode-select --install

2. After executing the above command, a software installation prompt window will pop up automatically. Click the [Install] button to install. ( This software is about 130MB )

The above steps can replace the installation of Xcode software to ensure the successful installation of nvm software.

3. Open the "Terminal" window and enter the following command to install the nvm software online:

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

It should be noted here : nvm can only be installed online through commands. Therefore, make sure that the computer can be connected to the Internet before installation.

4, after the installation is successful, the "terminal" window, enter nvma command, verify that the installation was successful nvm.

Two, use nvm to install Node.js

The following operations are all done in the "Terminal" window.

1. Install the specified version of Node.js

We can install the specified version of Node.js online through the following nvm command.

nvm install [nodeversion]

For example, you need to install the v6.9.1 version of Node.js, which can be done with the following command.

nvm install v6.9.1

2. Specify the Node.js version currently in use

Through nvm, multiple versions of Node.js can be installed at the same time, and we can specify the use of a certain version.

nvm use [nodeversion]

For example, if you need to use the v6.9.1 version of Node.js, you can use the following command to complete.

nvm use v6.9.1

3. View the list of currently installed Node.js versions

Since multiple Node.js can be installed through nvm, too many versions are difficult to manage. We can also check which version of Node.js is currently installed at any time.

nvm ls

4. Other commands of nvm

nvm also provides some commands for us to manage the version of Node.js.

  • nvm uninstall [nodeversion]: Indicates to delete the specified version of Node.js, the usage is similar to the install command.
  • nvm current: Indicates that the currently used Node.js version is displayed.
  • nvm reinstall-packages [npmversion]: Indicates that the specified version of the npm package manager is installed under the current Node.js version.

3. The significance of installing multiple versions of Node.js

Since the establishment of the Node.js Foundation, Node.js has had a release plan, that is, two release versions exist at the same time: a stable version and a trial version.

In Node.js, the stable version with long-term support (LTS) starts with an even number (4, 6, 8...), while the experimental version starts with an odd number (5, 7...). We recommend using the LTS version in a production environment and using the experimental version to try new things.

Four, nvm software switch mirror source

Because the country is somewhat special in some circumstances. The official image source of Node.js is abroad. When Node.js is often installed via nvm, the speed is slow or there is no response.

According to this situation, nvm allows to change the installed mirror source, we can switch the mirror source to the mirror source provided by domestic Taobao.

According to the official help documentation provided by nvm, we can switch through the following commands.

export NVM_NODEJS_ORG_MIRROR="http://npm.taobao.org/mirrors/node"

http://npm.taobao.org/mirrors/node is the domestic Node.js installation mirror source provided by Taobao NPM mirror .

What we need to note here is that this method will fail every time you restart the "terminal". In other words, you need to execute the above command every time you open the "terminal".

If you do not want every time you open the "terminal", you need to re-set the NVM_NODEJS_ORG_MIRRORenvironment variable.

  • If the "terminal" is used bash Shell, then (usually the Mac terminal default) to ~/.bash_profile(file , if not, automatically created ) add the following:
# nvm
export NVM_NODEJS_ORG_MIRROR="http://npm.taobao.org/mirrors/node"
source ~/.nvm/nvm.sh
  • If the "terminal" is used zsh Shell, then (usually Mac developers)
    to ~/.zshrc(file , if not, automatically created ) add the following:
# nvm
export NVM_NODEJS_ORG_MIRROR="http://npm.taobao.org/mirrors/node"
source ~/.nvm/nvm.sh

Nvm-windows software for Windows system

The function of the nvm-windows software of the Windows system is the same as the nvm software of the MacOS system. We can regard the nvm-windows software as the windows version of the nvm software.

For the introduction of nvm-windows software, you can visit the github homepage of nvm-windows .

1. Install nvm-windows software

Installing nvm-windows software is relatively simple. We only need to visit https://github.com/coreybutler/nvm-windows/releases and download the latest version of the installation file.

It should be noted that thenvm-setup.zip compressed file is the installation compressed package of the nvm-windows software. Download and unzip to install.

Two, nvm-windows software switch mirror source

We can find the software installation directory nvm-windows in the settings.txtfile, add the following:

node_mirror=http://npm.taobao.org/mirrors/node/

After adding successfully, you need to reopen the command line window.

Guess you like

Origin blog.csdn.net/u013575441/article/details/108743099