在 Ubuntu 系统中更新 Node.js 的方法有以下几种:
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
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 ~/.bashrc
nvm install node
nvm use node
node -v
npm -v
sudo apt-get update
sudo apt-get upgrade nodejs
node -v
npm -v
注意:使用此方法可能会导致 Node.js 版本不是最新的。建议使用 NodeSource 或 NVM 进行更新。