在 CentOS 上升级 Node.js 版本,你可以选择使用 NodeSource Repository 或者 NVM(Node Version Manager)
方法一:使用 NodeSource Repository
sudo yum remove nodejs
sudo yum groupinstall "Development Tools"
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum install nodejs
node -v
npm -v
方法二:使用 NVM(Node Version Manager)
sudo yum remove nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bash_profile
nvm install --lts
nvm use --lts
node -v
npm -v
现在,你已经成功地在 CentOS 上升级了 Node.js 版本。如果你想切换到其他版本,只需使用 nvm use <version>
命令。