Node.js 安装教程(Linux)
Linux 的发行版很多,下面给你最常见的三套方案:Ubuntu/Debian、Fedora/RHEL、Arch。
Ubuntu / Debian(推荐用 NodeSource)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -sudo apt-get updatesudo apt-get install -y nodejs
Fedora / RHEL
sudo dnf install -y nodejs npm
Arch Linux
sudo pacman -S --noconfirm nodejs npm
常见问题
npm 全局安装提示权限错误
不建议用 sudo npm -g 解决所有问题。更稳的做法是使用 nvm 管理 Node 版本和全局包目录。
npm 下载慢(可选)
如果你在国内网络环境,npm 下载慢,可以切换镜像(可随时改回去):
npm config set registry https://registry.npmmirror.com
查看是否切换成功:
npm config get registry