What is Node.js?

Node.js® is a JavaScript runtime based on the Chrome V8 engine 😂, this article does not describe in detail, to learn more about Node.js, you can read The teacher Pu Ling “Simple Node.js”, absolutely benefit.

  • Turing Community: Simple Node.js
  • Node.js official website: https://nodejs.org/zh-cn/
Why do YOU need a version management tool?
  • The version management tool allows you to quickly install and switch between different versions of Node.js on the same machine, in order to solve the problem of incompatibility between different versions of Node.js.
  • If you want to test modules developed using the latest frontier without uninstalling a stable version of Node, a version management tool can help.
What are the version management tools available?

nvm

Node.js Version Management NVM is a node.js Version Management tool. It is supported on macOS, Linux (including the Windows subsystem for Linux), and various other Unix-like systems. Due to poor Windows support, nVM-Windows was incubated by the community for Windows use, and they were supported and maintained separately from each other under different projects.

  • Linux, Mac OS:github.com/nvm-sh/nvm
  • Windows:Github.com/coreybutler…

n

Node.js versioning: No subshells, no config file Settings, no complex apis, just simple. The same level of system support as NVM is supported on macOS, Linux (including the Windows subsystem for Linux), and various other Unix-like systems.

  • Linux, Mac OS:github.com/tj/n
  • Windows: must work through WSL (the Windows subsystem of Linux)

nodenv

Node.js version management tool, forked from Rbenv, uses NodeEnv to select a Node version for your application and ensure that your development environment matches your production environment. Use nodeEnv with NPM for painless Node upgrades and bulletproof deployment.

  • Github.com/nodenv/node…

. Wait, wait, wait, wait, wait, wait, wait, wait, wait, wait.

NVM installation and use

Nvm-windows: Windows version

1. Download the installation package

Github.com/coreybutler…

Download the latest nVM-setup.zip file.

2. Install the NVM

3. Verify the installation

Open CMD and run the NVM command. The version number and command help information are displayed. The installation is successful.

4. Common commands

4.1 Viewing all locally installed versions

Arch, which specifies whether to install the 32-bit or 64-bit version (the default is the system version).

  • nvm list [available]
  • nvm list [available] [arch]
nvm list
Copy the code

4.2. Install the specified Node.js version

Version Latest Latest installation version

  • npm install latest
nvm install 14.171.
Copy the code

4.3. Switch to the specified version

NVM use 11 [arch] Arch (Optional) Specifies whether to install the 32-bit or 64-bit version (the default is the system version).

nvm use [version]
Copy the code

4.4. Uninstall the specified version

nvm uninstall 14.171.
Copy the code

4.5. Set the mirror source for Node and NPM

Use NVM node_mirror and NVM npm_mirror without specifying the URL to restore the default source

nvm node_mirror http://npm.taobao.org/mirrors/node/
nvm npm_mirror https://npm.taobao.org/mirrors/npm/
Copy the code

Nvm-sh: Linux, Mac OS and other Unix versions

1. Download and install
curl -o- https:/ / raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Copy the code

Or Wget:

wget -qO- https:/ / raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Copy the code

Note that v0.38.0 is the version number of NVM. The current latest version is V0.38.0

2. Verify the installation

After the installation is complete, close the terminal and restart the terminal. Enter NVM to verify whether the installation is successful. If Node Version Manager is displayed, the installation is successful.

3. Troubleshooting

Linux 3.1.

On Linux, if you get Command not found from the terminal after typing or don’t see any terminal feedback after typing Command -v NVM after running the installation script, simply shut down the current terminal, open a new terminal, and try again. Alternatively, you can run the following commands on the command line for different shells:

  • bash: source ~/.bashrc
  • zsh: source ~/.zshrc
  • ksh: . ~/.profile

3.2 Mac OS

If you get NVM: Command Not found after running the installation script, it could be for one of the following reasons:

  • As of macOS 10.15, the default shell is that ZSHNVM will look for.zshrc updates that are not installed by default. Create a touch ~/.zshrc and run the installation script again.
  • If you use bash (the previous default shell), your system may not have a file for the.bash_profile setup command. Create a touch ~/.bash_profile and run the installation script again. Then, run source ~/.bash_profile to get the NVM command.
  • You have used bash before, but you have ZSH installed. You need to manually add these lines to ~/.zshrc and run. ~/.zshrc.
  • You may need to restart the terminal instance or run. ~/.nvm/nvm.sh. Restarting the terminal/opening a new TAB/window, or running the source command will load the commands and the new configuration.
  • If this does not help, you may need to restart the terminal instance. Try opening a new TAB/window in terminal and try again.

If the above methods do not solve the problem, you can try the following methods:

  • If you use bash, it is possible that your.bash_profile (or ~/.profile) did not get your ~/.bashrc correctly. You can solve this problem by adding source ~/

    to it or by following the next steps below.
  • Try adding the fragments from the installation section to your usual configuration files (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) to find the correct NVM directory and load the NVM.
  • For more information about this problem and its resolution, see here

If you think the article is good, don’t forget to like and bookmark, your encouragement is my motivation to persist ~~~