在 CentOS 上配置 Node.js 镜像(国内加速),通常有两种常见需求:
下面分别说明。
sudo yum install -y curl
以 Node.js 18.x 为例:
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_18.x/setup | sudo bash -
然后安装:
sudo yum install -y nodejs
验证:
node -v
npm -v
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
或国内镜像:
curl -o- https://gitee.com/mirrors/nvm/raw/master/install.sh | bash
编辑 ~/.bashrc 或 ~/.zshrc:
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
export NVM_IOJS_ORG_MIRROR=https://npmmirror.com/mirrors/iojs
使配置生效:
source ~/.bashrc
nvm install 18
nvm use 18
npm install express --registry=https://registry.npmmirror.com
npm config set registry https://registry.npmmirror.com
查看:
npm config get registry
yarn config set registry https://registry.npmmirror.com
source ~/.bashrc
或检查 PATH:
echo $PATH
✅ nvm + npmmirror
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
nvm install 18
npm config set registry https://registry.npmmirror.com
如果你愿意,可以告诉我:
我可以给你一套最适合你环境的配置方案。