在 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 -
你可以将 setup_14.x 替换为你想要安装的 Node.js 版本,例如 setup_12.x。
sudo yum install nodejs
node -v
npm -v
方法二:使用 NVM(Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bash_profile
或者
source ~/.zshrc
(取决于你使用的 shell)
nvm install node
nvm use node
node -v
npm -v
现在你已经成功地在 CentOS 上升级了 Node.js 版本。如果你想要切换到其他版本,只需使用 nvm use <version> 命令。