jimmy@MacBook-Pro ~ % brew -v Homebrew 4.0.15-84-g9d5b017 Homebrew/homebrew-core (git revision c04886e1f63; last commit 2023-04-27) Homebrew/homebrew-cask (git revision 665ba9139d; last commit 2023-04-27) jimmy@MacBook-Pro ~ %
升级
$ brew update $ brew upgrade node
安装
# download and install Node.js brew install node@20 # verifies the right Node.js version is in the environment node -v # should print `v20.14.0` # verifies the right NPM version is in the environment npm -v # should print `10.7.0`
https://blog.csdn.net/m0_60437766/article/details/132116277
电脑上的版本太老了。删除重新下载安装
https://nodejs.org/en/download/prebuilt-installer
由于使用安装包的形式安装的,所以网上的卸载命令不起作用。
直接通过命令删除:
#删除 Node、npm jimmy@MacBook-Pro npm % sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*} # 验证 jimmy@MacBook-Pro npm % node -v zsh: command not found: node jimmy@MacBook-Pro npm % npm -v zsh: command not found: npm jimmy@MacBook-Pro npm %
重新安装
安装后验证
jimmy@MacBook-Pro npm % node -v v20.14.0 jimmy@MacBook-Pro npm % npm -v /usr/local/lib/node_modules/npm/lib/cli/validate-engines.js:31 throw err ^ Error: ENOENT: no such file or directory, uv_cwd at process.wrappedCwd (node:internal/bootstrap/switches/does_own_process_state:144:28) at process.cwd (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19) at new Config (/usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:71:19) at new Npm (/usr/local/lib/node_modules/npm/lib/npm.js:66:19) at module.exports (/usr/local/lib/node_modules/npm/lib/cli/entry.js:20:15) at module.exports (/usr/local/lib/node_modules/npm/lib/cli/validate-engines.js:39:10) at module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:4:31) at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:25) at Module._compile (node:internal/modules/cjs/loader:1358:14) at Module._extensions..js (node:internal/modules/cjs/loader:1416:10) { errno: -2, code: 'ENOENT', syscall: 'uv_cwd' } Node.js v20.14.0 jimmy@MacBook-Pro npm %
删除重安装
jimmy@MacBook-Pro ~ % sudo rm -rf /usr/local/lib/node_modules jimmy@MacBook-Pro ~ % sudo rm -rf .npm