阅读量:35
在 Ubuntu 系统中更新 Node.js 版本,你可以选择使用 NodeSource 存储库或者使用 NVM(Node Version Manager)。下面是两种方法的详细步骤:
方法一:使用 NodeSource 存储库
- 首先,删除已安装的 Node.js:
sudo apt-get remove nodejs
sudo apt-get autoremove
- 安装必要的软件包:
sudo apt-get update
sudo apt-get install curl software-properties-common
- 添加 NodeSource 存储库。请将
maverick替换为你需要的 Node.js 版本代号。例如,如果你想安装最新的 LTS 版本,可以使用nodist:
curl -fsSL https://deb.nodesource.com/setup_maverick.x | sudo -E bash -
- 安装 Node.js:
sudo apt-get install -y nodejs
- 检查 Node.js 版本:
node -v
npm -v
方法二:使用 NVM(Node Version Manager)
- 首先,安装 NVM。在你的终端中运行以下命令:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
- 安装完成后,关闭并重新打开终端。运行以下命令以确保 NVM 安装成功:
nvm --version
- 使用 NVM 安装最新的 Node.js 版本:
nvm install node
- 切换到新安装的 Node.js 版本:
nvm use node
- 检查 Node.js 版本:
node -v
npm -v
现在你已经成功更新了 Ubuntu 系统中的 Node.js 版本。如果你想切换到其他版本,只需使用 nvm use 命令。