在 Ubuntu 系统中更新 Node.js 版本,你可以选择使用 NodeSource 存储库或者使用 NVM(Node Version Manager)。下面是两种方法的详细步骤:
方法一:使用 NodeSource 存储库
sudo apt-get remove nodejs
sudo apt-get autoremove
sudo apt-get update
sudo apt-get install curl software-properties-common
maverick
替换为你需要的 Node.js 版本代号。例如,如果你想安装最新的 LTS 版本,可以使用 nodist
:curl -fsSL https://deb.nodesource.com/setup_maverick.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
方法二:使用 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
现在你已经成功更新了 Ubuntu 系统中的 Node.js 版本。如果你想切换到其他版本,只需使用 nvm use <version>
命令。