After upgrading the npm command separately on the mac system, the npm command cannot be used because the node version is too low and has not been upgraded in advance:
ERROR: npm v9.6.2 is known not to run on Node.js v10.15.1. You'll need to upgrade
to a newer Node.js version in order to use this version of npm. This version of
npm supports the following node versions: `^14.17.0 || ^16.13.0 || >=18.0.0`. You
can find the latest version at https://nodejs.org/.
ERROR:
/usr/local/lib/node_modules/npm/lib/utils/exit-handler.js:21
const hasLoadedNpm = npm?.config.loaded
This problem of not being able to use a higher version of npm because the node version is relatively low, the usual solution:
1. View the current version
node -v
2. Clear the cache of Node.js
sudo npm cache clean -f
3. Use npm to install the n module, here I use the Node.js multi-version manager n to upgrade
sudo npm -gn
4. View all versions of node
npm view node versions
5. Upgrade the version, here I chose to upgrade to a stable version
sudo n latest. //upgrade the latest version
sudo n stable //upgrade stable version
sudo n XX.XX. //Upgrade to the specified version
6. View version
node -v //View the latest version after upgrade
In this process, because the npm command has expired and cannot be used, step 3 cannot be executed successfully. At this time, you can use Homebrew of mac to achieve: brew install n
After successful execution, you can view the version number: n --version
Other:
There is an error prompt at the end of the n command installation, Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins
Can be executed by: sudo chown -R $(whoami) $(brew --prefix)/*
Another method (untested):
mkdir -p /Applications/Docker.app/Contents/Resources/cli-plugins
brew cleanup
Additional commands:
1. Node version downgrade/upgrade (install specified node version)
sudo n 版本号 // 例如:sudo n 10.16.0
2. Uninstall the specified node version
sudo n rm 版本号
3. Detect which node versions are currently installed
n
4. Switch node version (other versions installed will not be deleted)
sudo n 版本号
5. Update npm to the latest version
sudo npm install npm@latest -g
6.cnpm install lower version
npm install -g [email protected] --registry=https://registry.npm.taobao.org
A collection of commands used in solving the problem:
brew update
brew upgrade node
npm install -g npm
--
brew update && brew upgrade node && npm install -g npm
--
brew install nvm
nvm install node
--
nvm install 0.8.22
nvm list
nvm use 0.8.22