Steps and problems of installing nvm on Mac

nvm:

  Node Version Manager, a tool for managing node package versions.

nvm installation steps:

1. Install node

If you have not installed node before , skip this step. If you have installed node before, uninstall node first.

# Uninstall npm

npm uninstall npm -g

#Check whether npm is uninstalled

npm -v

#Uninstall node

sudo rm /usr/local/bin/node

#Check whether node is uninstalled

node -v

2. Enter the following command in the terminal to download nvm

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

The link can be found in github/nvm

Problems that arise:

Failed to connect to raw.githubusercontent.com port 443,couldn't find the server.

Solution:

1. Use the proxy address, go to https://ipaddress.com and enter the address raw.githubusercontent.com to find the corresponding IP.

 

 

2. Enter sudo vim /etc/hosts in the terminal to edit the hosts file and add the IP address of raw.githubusercontent.com.

 

3. Enter the hosts file, press the ℹ️ button to enter the writing mode, write the corresponding IP and address, and press the esc key to exit the editing mode after writing. Type:wq and press Enter.

 

4. Enter cat /etc/hosts in the terminal to check the hosts, whether they are added and the ip and address.

5. Configure environment variables and add the bash.profile file.

(1) Enter touch .bash_profile in the terminal to create the .bash.profile file.

(2) Enter open .bash_profile in the terminal and edit the .bash.profile file.

(3) Add the following code to the pop-up .bash.profile file

#nvm
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

(4) Enter nvm -v on the terminal to output the version number, which means the installation is successful.

6. When downloading nvm, it is best to connect to the mobile hotspot to avoid failure to download nvm due to connection timeout.

3. Common commands of nvm

nvm ls //View installed version

nvm node version number //Switch to the specified version of node (preferably an even-numbered version of node, more stable)

nvm install node version number //Install the specified node version number

nvm install stable //Install the latest version of node

nvm ls -remote //List remote versions

nvm alias default version number //Set the local default node version

nvm current //View the currently used node version

Guess you like

Origin blog.csdn.net/qq_54956455/article/details/130387143