必须同时完成Node.js运行时安装、npm就位和国内镜像生效三件事:用apt/dnf/yum一键装Node.js和npm,立即验证node -v与npm -v;全局执行npm config set registry https://registry.npmmirror.com,并确认生效,旧taobao源已停服。

在Linux系统上快速搭建可用的Node.js开发环境,必须同时完成Node.js运行时安装、npm包管理器就位、以及国内镜像源生效三件事——缺一不可,否则后续执行npm install会卡死或报SSL证书错误。
用包管理器一键安装Node.js和npm
Ubuntu/Debian系统执行:sudo apt update && sudo apt install -y nodejs npm
CentOS/RHEL 8+系统执行:sudo dnf module install nodejs:18(启用18.x LTS模块)
RHEL 7/CentOS 7系统执行:curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash - && sudo yum install -y nodejs
安装完成后立即验证:node -v和npm -v必须都输出版本号;若提示Command 'npm' not found,说明系统拆分了包,补装:sudo apt install npm
配置npm使用https://registry.npmmirror.com
旧taobao源registry.npm.taobao.org已停服,继续使用会导致ERR_SSL_CERT_HAS_EXPIRED错误。
执行全局设置:npm config set registry https://registry.npmmirror.com
exa-js 是 Exa 官方 JavaScript 软件开发工具包,Exa 是一个为 AI 工作流构建的网络搜索 API。它为代理提供了一种具体的方式来搜索网络、检索页面内容,并从代码中生成有来源的答案,而不是手动拼接原始 HTTP 调用。
验证是否生效:npm config get registry输出必须是https://registry.npmmirror.com,不能以http://开头,也不能带尾部斜杠
如果仍连不上,检查~/.npmrc文件里是否有重复或冲突的registry=行,手动删除旧配置;也可强制写入全局:npm config set -g registry https://registry.npmmirror.com
临时换源与多镜像切换(可选)
方法一:单次命令指定镜像
执行npm install axios --registry=https://registry.npmmirror.com,仅本次生效
方法二:用nrm管理镜像源
先全局安装:npm install -g nrm
查看可用源:nrm ls
切换到淘宝镜像:nrm use npmmirror
方法三:手动切换其他国内镜像
中科大:npm config set registry https://npmreg.proxy.ustclug.org/
清华:npm config set registry https://mirrors.tuna.tsinghua.edu.cn/npm/
华为云:npm config set registry https://mirrors.huaweicloud.com/repository/npm/
【注意】nrm use命令不会覆盖全局registry配置,而是将当前shell会话的registry临时指向对应源,退出终端即失效


















