Remember before

Changed computer, stepped in some potholes while installing NVM, take note.

I initially installed Node using Homebrew and decided to use NVM to centrally manage node versions, so I had to uninstall the nodes I had downloaded.

Uninstall node modules

If, like me, you already have Node installed globally, it’s best to remove this to avoid unnecessary conflicts later.

View modules that have been installed globally
npm ls -g --depth=0
Delete the global node_modules directory
sudo rm -rf /usr/local/lib/node_modules
# remove node
sudo rm /usr/local/bin/node 
# delete global Node module registration soft link
cd /usr/local/bin && ls -l | grep ".. /lib/node_modules/" | awk '{print $9}'| xargs rm
Copy the code

Install the NVM

Before downloading NVM, check whether the.bash_profile file exists in the current user’s home directory. If not, create it first.

There is no need to do any writing to the file after it is created, because when NVM is downloaded later, it will automatically find the new file and write to it.

I’ve seen a lot of tutorials online that require you to actively write to.bash_profile, but you don’t have to.

# 1. Create.bash_profileTouch ~ /. Following# 2. Run the download/update scriptThe curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bashCopy the code

nvm: command not found

Unfortunately, after downloading the tutorial, I tried the following methods: restart the terminal, copy the.bash_profile file in the NVM folder, manually modify the configuration file, etc., and the result still told NVM: Command not found.

Later I found that source ~/.bash_profile works every time I execute it (my new profile), but only once.

Eventually I found a solution, probably because my system is the latest updated macOS Catalina system, the default shell is ZSH, so I can’t find the configuration file or anything.

Solutions are as follows:

# 1. Create a.zshrc file (if you don't have one)
touch ~/.zshrc
# 2. Add a line at the end of the ~/.zshrc file
source ~/.bash_profile
Copy the code

Install the node

# Latest stable release
nvm install stable
Copy the code

Refer to the article

Installing NVM Management Node on Mac (Solution)