Install nvm on Mac
Due to changes in the project and the relationship between dependencies, we have to use multiple node versions to manage our projects. nvm provides us with a way to switch node environments. Follow my blog to implement multi-version node management on your mac.
If you are using zshShell please see the following configuration
Delete the node installed by pkg
sudo rm -rf /usr/local/{
bin/{
node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
Delete the node installed by brew
brew uninstall node
After node uninstall is completed
brew install nvm
After the installation is complete, a piece of content will be displayed
You should create NVM's working directory if it doesn't exist:
mkdir ~/.nvm
Add the following to ~/.config/fish/config.fish or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.
Based on the above information, we know that the above content should be added to the configuration file.
Open zsh Config and copy the following content to .zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
export NVM_NODEJS_ORG_MIRROR = https://npm.taobao.org/mirrors/node # 由于节点在国外在这里换镜像源
vim ~/.zshrc
After saving, open a new terminal or reload the configuration file in the original terminal window.
source ~/.zshrc
If you are using fishShell please see the following configuration
Install bass (if the installation fails or the package is dropped, please configure the agent in the terminal)
omf install bass
Open config.fish
vim ~/.config/fish/config.fish
Copy the following code to config.fish (please refer to the actual path in the mac for the source path in the code)
function nvm
bass source /Users/apple/.nvm/nvm.sh ';' nvm $argv
end
In the end, still use the previous operation (just open a new terminal or reload the configuration file in the original terminal window)
source ~/.config/fish/config.fish
Finally
You are welcome to point out any errors or imperfections mentioned above. Follow me and don’t get lost~