This is the first day of my participation in the Gwen Challenge in November. Check out the details: the last Gwen Challenge in 2021
Node iterates quickly, so there are currently many versions of Node that coexist.
There are a number of packages that need a specific version of Node to run properly. LvLin found that gitbook-CLI did not run in the V16 version of Node.
What do you do when you encounter a Node environment mismatch? The solution is simple, just add more (it’s painful just to think about it).
In order to deal with the problem of multiple node version switching, a number of node version management tools have emerged in the industry: NVM, NVS, N. This article mainly introduces the installation and use of NVM and NVM – Windows.
nvm
The Node version management tool supports MAC and Linux operating systems. Windows uses NVM-Windows instead.
Because LvLin uses Windows system, so here is only an introduction, not a demonstration, specific use can refer to NVM-Windows.
The installation
Install using shell script:
$The curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Copy the code
After the installation is complete, check whether the following fragment exists in the configuration file ~/.bashrc. If not, add it manually:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Copy the code
Execute the source command to make the system environment variables take effect:
$ source ~/.bashrc
Copy the code
After installing NVM, view the version number:
$ nvm --version
Copy the code
For more installation methods, refer to the official warehouse.
use
List the node versions currently available for NVM installation:
$ nvm ls-remote
Copy the code
Install the specific version:
$NVM install 14.18.0
$ nvm install 8
Copy the code
List the installed Versions of Node:
$ nvm ls
Copy the code
Switch node versions:
$ nvm use 8
Copy the code
When we install global packages on Node 14 and switch to Node 8, these packages need to be reinstalled to use.
You can then install the global package with one click via the NVM Scander-Packages directive.
$NVM use 14.18.0
$ nvm reinstall-packages 8
Copy the code
As a result, the same global packages are installed in the V8 node environment as in the V14 node environment.
nvm-windows
NVM does not support Windows, so we use NVM-Windows instead.
The installation
Download the installation package from the NVM-Windows repository and unzip it to install it.
If it can’t be downloaded, you can pay attention to LvLin’s public number [play point front end] and send keywords [NVM] to obtain network disk resources for download.
After the installation is complete, open PowerShell as an administrator and enter NVM version to check whether the installation is successful.
> nvm version
1.1.8
Copy the code
use
NVM list available: Lists the node versions available for installation. You can abbreviate NVM ls available.
NVM install: Installs the specified version of Node. Install node v16.12.0 and V14.18.0 as shown below:
NVM list: View the installed node version. You can abbreviate it to NVM ls.
> nvm list
16.12.0
14.18.0
Copy the code
NVM use
: Use the node environment of the specified version.
You can view the current node version using NVM List or NVM Current.
NVM uninstall
: Uninstalls the specified version of node.
>NVM uninstall 14.18.0Uninstalling the node v14.18.0... doneCopy the code
NVM node_mirror [url] : switch node mirror source. NVM npm_mirror [url] : switch NPM mirror source.
> nvm node_mirror https://npm.taobao.org/mirrors/node/
> nvm npm_mirror https://npm.taobao.org/mirrors/npm/
Copy the code
More commands can be viewed through NVM.
abnormal
-
When exit status 1 appears, it is usually due to insufficient permissions and the need to run PowerShell as an administrator.
nvm-windows runs in an Admin shell. You’ll need to start
powershell
or Command Prompt as Administrator to use nvm-windows -
NPM installation package is abnormal. Try switching to taobao image source.
Method 1: NVM npm_mirror https://npm.taobao.org/mirrors/npm/
Method 2: Locate the settings. TXT file in the NVM installation folder and add the image source configuration:
root: C:\nvm path: C:\nodejs + node_mirror: http://npm.taobao.org/mirrors/node/ + npm_mirror: https://npm.taobao.org/mirrors/npm/ Copy the code