Skip to content

Linux 平台

在 Linux 上安装 Node.js 运行环境。以下命令适用于 Ubuntu / Debian,其它发行版请做相应替换。

方法一:NodeSource 官方脚本

bash
# Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# 验证
node -v
npm -v

方法二:nvm(推荐)

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc

nvm install 20
nvm use 20
nvm alias default 20

CentOS / RHEL / Rocky

bash
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejs

Alpine(Docker 场景常见)

bash
apk add --no-cache nodejs npm

换源

bash
npm config set registry https://registry.npmmirror.com

和谐、友善、互助、开心