要在 CentOS 上升级 Node.js 版本,您可以使用 NodeSource 存储库或 NVM(Node Version Manager)。下面是使用这两种方法的详细步骤:
方法 1:使用 NodeSource 存储库
sudo yum remove nodejs
sudo yum install -y curl gcc-c++ make
lts/*
替换为所需的版本,例如 14.x
。curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs
node -v
方法 2:使用 NVM(Node Version Manager)
sudo yum remove nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bash_profile
或者
source ~/.bashrc
nvm install --lts
要安装特定版本,请运行:
nvm install <version>
将 <version>
替换为您需要的版本,例如 14.x
。
nvm use <version>
将 <version>
替换为您需要的版本,例如 14.x
。
node -v
现在,您已经成功地在 CentOS 上升级了 Node.js 版本。如果您需要切换到其他版本,只需使用 nvm use <version>
命令。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: oracle在centos上的故障排查指南