Mac uses brew to install nvm and step on the pit

1. brew installation

cd ~/

brew install nvm

nvm -v  (出现版本号证明安装成功)

nvm install v14.12.3 安装v14.12.3版本的node, 可根据情况安装其他版本

node -v 查看node版本

npm -v 查看npm版本

At this time, after the installation is successful, there will be 2 problems

1. Open a new command window again, or vscode opens a project terminal for execution, and nvm -v will display command not found (including installed node, npm),

2. Open a new command window again, or vscode opens a project terminal to execute source ~/.zshrc every time to find nvm, node, npm

Solve the first problem: common not found: nvm

(1) Enter the .nvm folder

cd ~/.nvm

(2) Check if there is a .bash_profile file

open directly if any

open .bash_profile

If not, create a new one and open it first

touch .bash_profile

(3) Add the following code to the .bash_profile file

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

(4) Close, and then execute the file

source .bash_profile

Then you can use the nvm command

Solve the second problem encountered later

(1) Open the .zshrc file

open ~/.zshrc

(2) Add the configuration to the .zshrc file

export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

source ~/.bash_profile

3) Execute the .zshrc file

source ~/.zshrc

Guess you like

Origin blog.csdn.net/z1712636234/article/details/129304431