mac m1安装和使用nvm的问题
使用nvm管理多版本node
每个项目可能用的node版本不同,所以需要多个版本node来回切换
但是最近遇到安装v14.19.0时一直安装失败的问题。
首先说明一下,用的电脑是mac M1芯片
Downloading and installing node v14.19.0...
Downloading https://nodejs.org/dist/v14.19.0/node-v14.19.0-darwin-arm64.tar.xz...
curl: (22) The requested URL returned error: 404 Binary download from https://nodejs.org/dist/v14.19.0/node-v14.19.0-darwin-arm64.tar.xz failed, trying source.
grep: /Users/wangsai/.nvm/.cache/bin/node-v14.19.0-darwin-arm64/node-v14.19.0-darwin-arm64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 8 CPU core(s)
Running with 7 threads to speed up the build
Clang v3.5+ detected! CC or CXX not specified, will use Clang as C/C++ compiler!
Local cache found: ${NVM_DIR}/.cache/src/node-v14.19.0/node-v14.19.0.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/src/node-v14.19.0/node-v14.19.0.tar.xz
$>./configure --prefix=/Users/wangsai/.nvm/versions/node/v14.19.0 <
Node.js configure: Found Python 3.9.7...
解决思路:
1、去node 官网查v14.19.0的版本,发现没有node-v14.19.0-darwin-arm64/node-v14.19.0-darwin-arm64.tar.xz 文件,所以肯定下载不下来。
2、那怎么操作能安装这个版本呢,查了解决办法可以使用以下操作解决
修改~./zshrc在开头加入下面两行:
autoload -Uz compinit
compinit
添加完的文本内容如下:
autoload -Uz compinit
compinit
export PATH="/opt/homebrew/opt/node@12/bin:$PATH"
export PATH="/opt/homebrew/opt/node@14/bin:$PATH"
export PATH="/opt/homebrew/opt/node@16/bin:$PATH"
export PATH="/usr/local/bin:$PATH"export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export PATH="/opt/homebrew/opt/node@14/bin:$PATH"
然后执行**arch -x86_64 zsh
**后再安装即可。
arch -x86_64 zsh
再次安装
nvm install 14.19.0
下载过程中可以看到下载的文件是node-v14.19.0-darwin-x64.tar.xz 这个文件在node官网是存在的。
就可以下载安装成功了