Node version management (nvm)

During the development process, it may be necessary to switch node versions frequently to cope with different development environments, so different versions of node are required. The following will introduce the use of nvm to manage node versions.

1. nvm download

1) nvm installation under Windows
The installation steps are as follows:
First, download it from github. Download address: https://github.com/coreybutler/nvm-windows/releases
Second, after downloading nvm-setup.zip, unzip it, and extract a nvm-setup.exe file
Third, double-click to install
Fourth, open cmd , enter nvm to verify whether the installation is successful or not.
Fifth, note:
nvm-noinstall.zip: Green free installation version, but it needs to be configured when using it.
nvm-setup.zip: installation version, it is recommended to use
nvm installation path can be customized, such as: d:\nvm
node.js installation path (it is the installation path of different versions of node.js downloaded later, it is recommended not to put it on the C drive, Do not have spaces, special characters, etc.): For example: d:\node.js
2) Install with nvm under Windows,
you can use the curl command to install

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

You can also use the wget command to install

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

v0.38.0 is the version number of nvm, and the latest version number can be found in github.
When the Node Version Manager appears, it means that the installation is successful;
after the installation is complete, you need to close the terminal first, and then reopen it.
You can confirm whether the installation is successful by checking the version number command:

nvm -v

If command not found: nvm appears, it may be caused by the lack of .bash_profile file.
Continue with the following steps to
switch to the user directory:

cd ~

Check if there is a .bash_profile file:

ls -a;

If not, create a new one and add the following

export NVM_DIR="$HOME/.nvm"[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

If oh my zsh is installed, you need to add configuration information in the .zshrc file; open the ~/.zshrc file, and add source ~/.bash_profile at the bottom. Note that the Mac system,
m1
chip, there will be compatibility issues .
Node.js v15.xx and above versions have been compatible with M1.
When installing node.js v14 and below versions, you need to enter Rosetta 2 and install the corresponding stable version

arch -x86_64 zshnvm listnvm install 12

2. Common commands of nvm

nvm ls : list all installed node versions

nvm ls-remote: list all remote server versions (official node version list)

nvm list : list all installed node versions

nvm list available : Show all available downloadable versions

nvm install stable : install the latest version of node

nvm install [node version number]: install the specified version node

nvm uninstall [node version number]: delete the specified version installed

nvm use [node version number]: switch to the specified version node

nvm current : current node version

nvm alias [alias] [node version number]: add aliases to different version numbers

nvm unalias [alias]: remove a defined alias

nvm alias default [node version number]: set the default version

When setting nvm use [node version number] to report an error, you can try to turn off cmd and run cmd again as an administrator

Guess you like

Origin blog.csdn.net/weixin_43899065/article/details/124730628