要在 Ubuntu 上更新 Node.js,请按照以下步骤操作:
打开终端(快捷键:Ctrl + Alt + T)
首先,删除已安装的 Node.js。使用以下命令卸载 Node.js 及其相关包:
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
sudo apt-get clean
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
请注意,上面的命令将安装 Node.js 16.x 版本。如果您想安装其他版本,请将 setup_16.x
替换为所需的版本,例如 setup_14.x
。
sudo apt-get install -y nodejs
node -v
npm -v
现在,您已经成功地在 Ubuntu 上更新了 Node.js。如果需要安装其他版本的 Node.js,可以重复上述步骤,并在步骤 4 中替换所需的版本号。