Mac updates the node version and corrects it to a new version (not installed using brew)

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

insert image description here
At this time, node -v found that it was still an old version

hanpeng@hanpeng nestplay01 % node -v
v18.0.0

brew unlinkUnlink 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

Guess you like

Origin blog.csdn.net/qq_37106501/article/details/130505299