First use node -v to view the current version
hanpeng@hanpeng nestplay01 % node -v
v18.0.0
1. Clear the cache of nodejs
sudo npm cache clean -f
2. Use npm to install the multi-version manager of Node.js n
sudo npm install -g n
3 View all versions available
npm view node versions
Four install the latest version or specified version
// Upgrade to the latest version sudo n latest
// Upgrade to a stable version sudo n stable
// Upgrade to a specific version number sudo n xx.xx
hanpeng@hanpeng nestplay01 % sudo n 18.16.0
installing : node-v18.16.0
mkdir : /usr/local/n/versions/node/18.16.0
fetch : https://nodejs.org/dist/v18.16.0/node-v18.16.0-darwin-arm64.tar.xz
copying : node/18.16.0
installed : v18.16.0 to /usr/local/bin/node
active : v18.0.0 at /opt/homebrew/bin/node
At this time, node -v found that it was still an old version
hanpeng@hanpeng nestplay01 % node -v
v18.0.0
brew unlink
Unlink with one command
hanpeng@hanpeng nestplay01 % brew unlink node
Unlinking /opt/homebrew/Cellar/node/18.0.0... 7 symlinks removed.
hanpeng@hanpeng nestplay01 % node -v
v18.16.0