在 Ubuntu 上升级 Node.js 的方法有很多种,以下是其中两种常用的方法:
方法一:使用 nvm(Node Version Manager)
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
安装完成后,关闭并重新打开终端。
使用以下命令查看可用的 Node.js 版本:
nvm ls-remote
nvm install --lts
nvm use --lts
node -v
npm -v
方法二:使用 Ubuntu 软件包管理器
sudo apt update
sudo apt install nodejs npm
node -v
npm -v
请注意,使用此方法安装的 Node.js 版本可能不是最新的。如果您需要特定版本,请考虑使用 nvm。