1. Install the NVM

Run the following command to manage Node versions

Because some frameworks have rigid requirements for Node versions, NVM is a must-have tool for those who need to maintain multiple versions of frameworks on one machine at the same time. It provides us with simple installation, update, and switch Node versions

Mac

// Install via Homebere
// PS: Homebrew is a software package management tool for macOS. The recommended official website is http://brew.shBrew install NVM After Homebrew is installed, the computer generally cannot recognize the NVM command, so you need to configure environment variables to open the command line:1.Create file: touch.bash_profile// The configuration file already exists can be skipped
2.Edit the file: vi. Bash_profile3.Modify the file: In the configuration file, enter:export NVM_DIR="$HOME/.nvm"
  . "/usr/local/opt/nvm/nvm.sh"
4.Save the configuration and exit: :wq5.Enable configuration: source.bash_profilePS: You need to run this command again after each restart of the computer for the configuration to take effect. For convenience, you can add the source ~/. Bash_profile command to the ~/Copy the code

Win

Installing NVM on Windows is relatively easy!! Note: If you already have NVM or Node installed on your computer, you are advised to clean it up before reinstalling NVM1.Download the installation package: HTTPS://github.com/coreybutler/nvm-windows/releases
// It is recommended to download nVM-setup.zip directly to save the step of configuring environment variables
2.Double click on the install3.Yes, it's that simpleCopy the code

Attached: some common commands for development

NVM install stable // Installing the latest stable version of Node It is not recommended to use NVM install<version> // Install the specified version of Node NVM. NVM uninstall<version> // Uninstall the specified version of Node NVM Use <version> // switch to the specified version of node NVM ls // check all installed versions of NVM current // Display the current version of Windows NVM does not support this command, can use NVM ls instead, The one preceded by * is the version currently in use (maOS also works)Copy the code

2. Install the Node using the NVM

As stated above,Win and macOS are consistent, so I won’t describe it too much here

Hit the pit

  • During the installation process, the installation went well on MAC, but I could not recognize the Node command after the installation on Win, probably because the management of Node by NVM is not enabled by default. You can try to use itnvm onCommand to turn on
  • In addition, if the configuration is complete after the appearancenode -vIt can be recognized normally, butnpm -vNPM cannot be automatically installed in node 8.11 or later. In addition to node.exe, there should be a corresponding NPM file in the node folder, but it can be found that the file is downloaded to the temp folder on the node level

Open the folder and decompress the NPM package to the corresponding folder. Otherwise, it will be deleted

3. Install NRM (on demand)

NRM (NPM Registry Manager) is the mirror source management tool of NPM. Sometimes foreign resources are too slow, so it can be used to quickly switch between NPM sources

NPM install NRM -gCopy the code

Commonly used instructions

NRM ls View all configured source NRM use <name> Switch source NRM add <name> <address> Configure the source NRMtestTest the latency of each source (you can run this command first and then pick the source with the lowest latency in the current network environment)Copy the code

This tool is mainly convenient for some students who need to switch the internal source of the company. In fact, there is no need to configure taobao mirror address. There is no need to install this tool

4. Install YARN (Recommended)

Yarn has similar functions to NPM, but has better performance and stability. When network resources are poor, yarn’s retry mechanism ensures that a single request failure does not cause the entire installation failure

npm install -g yarn
Copy the code