解决 Mac(M1/M2)芯片,使用node 14版本

前言

nvm 在安装 Node.js v14.21.3 时,报错:

复制代码
nvm install 14
Downloading and installing node v14.21.3...
Downloading https://nodejs.org/dist/v14.21.3/node-v14.21.3-darwin-arm64.tar.xz...
curl: (56) The requested URL returned error: 404

Binary download from https://nodejs.org/dist/v14.21.3/node-v14.21.3-darwin-arm64.tar.xz failed, trying source.
grep: /Users/niuben/.nvm/.cache/bin/node-v14.21.3-darwin-arm64/node-v14.21.3-darwin-arm64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
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.21.3/node-v14.21.3.tar.xz
Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/src/node-v14.21.3/node-v14.21.3.tar.xz
$>./configure --prefix=/Users/niuben/.nvm/versions/node/v14.21.3 <
Node.js configure: Found Python 3.12.6...
Please use python3.10 or python3.9 or python3.8 or python3.7 or python3.6 or python3.5 or python2.7.
nvm: install v14.21.3 failed!

这是因为 Node.js 官方并没有为 darwin-arm64 提供预编译二进制文件。

对于 M1/M2 芯片的 Mac,nvm 会尝试下载 darwin-arm64 版本,但由于文件不存在,它会自动回退到从源码编译的方式。

通过 Rosetta 2 安装并运行 x64 架构的 Node.js 14

通过 Rosetta 2 安装并运行 x64 架构的 Node.js 14

打开 Finder,找到你的终端应用(例如:Terminal 或 iTerm2), 右键点击终端应用,选择 "显示简介" ,勾选 "通过 Rosetta 打开",重启后,这样终端会以 x64 模式运行。

会发现 arch 结果是 i386架构

这时候,再执行 nvm install 14,就能顺利安装了

复制代码
nvm install 14

从源码编译 Node.js 14 的 ARM 架构版本

如果你希望运行原生的 ARM 架构版本(而不是通过 Rosetta),可以从源码编译 Node.js 14。

安装依赖

复制代码
brew install python@3.9
brew install gcc

# 如果系统默认 python 不符合要求,可以通过 python3.9 指定路径:
export PYTHON=$(brew --prefix python@3.9)/bin/python3.9

使用 nvm 编译并安装

执行以下命令,强制从源码编译 Node.js:

复制代码
nvm install 14 --build-from-source

这会使用源码编译 Node.js 14 版本,并安装。

相关推荐
携程DBA6 小时前
数据库软限制相关研究
linux·mysql·性能
huy1n96 小时前
Ubuntu 22.04部署Claude Code并接入DeepSeek-V4模型完整教程
linux·ubuntu·deepseek·claude code
诚信定制8397 小时前
使用 CLion 内置性能分析工具观察新特性开销
编辑器
ICECREAM7 小时前
I/O 多路复用完全指南 —— select、poll、epoll
linux
进阶的猪7 小时前
Linux 内核移植过程学习
linux·学习
z***刺8 小时前
VMware安装macOS安装教程(附安装包)2025超详细下载安装教程
其他·macos
ReaF_star8 小时前
【工具】把 eDiary 改造成了“云日记本”:两台 Mac 同步笔记的折腾记录
macos·效率工具·文件同步·icloud drive·ediary·mac 自动化
问简9 小时前
【共享盘】ubuntu、windows
linux·windows·ubuntu
小生不才yz10 小时前
Shell脚本精读 · S13-01 | POSIX sh 与 Bash:语法对照表
linux
阿拉斯攀登10 小时前
平台设备驱动:platform bus 与设备树
linux·嵌入式硬件·嵌入式·linux驱动·字符设备驱动