1

When multiple periods of nodejs projects exist at the same time, our computer needs to have the ability to quickly switch nodejs versions, and the best way to have this ability is to install a nodejs version management tool, namely nodejs version manager, referred to as nvm .

Installation Environment

  1. Operating system: macos
  2. Installed software: brew
  3. Already have an agent, which can ensure that brew can smoothly pull the installation package from foreign sites.

Install nvm

Open the shell and set the proxy parameters:

export http_proxy=127.0.0.1:7890
export HTTPS_PROXY=127.0.0.1:7890

The above two commands set up related agents for brew. Please change the agent parameters according to your actual situation.

Next, execute brew install nvm . After the installation is complete, you will get a successful installation prompt in the shell. This prompt also informs us that we need to perform some manual operations to ensure the correct operation of nvm

Create folder

After the installation is complete, you need to check whether the .nvm folder exists in the current user folder. If it does not exist, you need to manually create the .nvm file. The shortcut creation command is mkdir ~/.nvm .

Set environment variables

The next step is to set the environment variables. You can successfully execute nvm in any location, open the ~/.zshrc folder, and add the following code:

export NVM_DIR="$HOME/.nvm"
  [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Save the file and exit.

test

At this point we exit the shell and reopen one, execute nvm . If there is no prompt that we did not find the relevant command but a large help message appears, it means that the nvm installation was successful.

It should be noted that if you are also using the IDEA family of IDEs, you also need to exit the IDE and start a new shell to recognize the nvm command.


潘杰
3.2k 声望245 粉丝