在CentOS上更新Node.js,您可以使用NodeSource存储库或NVM(Node Version Manager)。下面是使用这两种方法的详细步骤:
方法1:使用NodeSource存储库
sudo yum remove nodejs
sudo yum install -y curl
curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs
node -v
npm -v
方法2:使用NVM(Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm --version
nvm install node
nvm use node
node -v
npm -v
现在,您已经成功地在CentOS上更新了Node.js。如果您想要切换到其他Node.js版本,只需使用nvm use <version>命令。