1、使用 NodeSource 仓库
- 设置 NodeSource 仓库
bash
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
上面的命令会安装 Node.js 16.x 版本。如果你想安装其他版本,可以替换 16.x 为其他版本号,例如 14.x 或 18.x。
- 安装 Node.js 和 npm
bash
sudo yum install -y nodejs
2、使用 NVM(Node Version Manager)
NVM 允许你管理多个 Node.js 版本。如果你需要管理多个版本或者想要更灵活地切换版本,NVM 是一个不错的选择。
- 安装 NVM
bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
或使用 wget
bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
- 验证安装
bash
nvm -v
- 安装node
bash
nvm install 14.8.0
- 切换node
bash
nvm use 14.8.0
3、验证安装
bash
node -v
bash
npm -v
如您在阅读中发现不足,欢迎留言!!!