ubuntu

ubuntu下如何更新nodejs版本

小樊
61
2025-05-01 11:36:32
栏目: 编程语言

在 Ubuntu 系统中更新 Node.js 版本,你可以选择使用 NodeSource 存储库或者使用 NVM(Node Version Manager)。下面是两种方法的详细步骤:

方法一:使用 NodeSource 存储库

  1. 首先,删除已安装的 Node.js:
sudo apt-get remove nodejs
sudo apt-get autoremove
  1. 安装必要的软件包:
sudo apt-get update
sudo apt-get install curl software-properties-common
  1. 添加 NodeSource 存储库。请将 maverick 替换为你需要的 Node.js 版本代号。例如,如果你想安装最新的 LTS 版本,可以使用 nodist
curl -fsSL https://deb.nodesource.com/setup_maverick.x | sudo -E bash -
  1. 安装 Node.js:
sudo apt-get install -y nodejs
  1. 检查 Node.js 版本:
node -v
npm -v

方法二:使用 NVM(Node Version Manager)

  1. 首先,安装 NVM。在你的终端中运行以下命令:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  1. 安装完成后,关闭并重新打开终端。运行以下命令以确保 NVM 安装成功:
nvm --version
  1. 使用 NVM 安装最新的 Node.js 版本:
nvm install node
  1. 切换到新安装的 Node.js 版本:
nvm use node
  1. 检查 Node.js 版本:
node -v
npm -v

现在你已经成功更新了 Ubuntu 系统中的 Node.js 版本。如果你想切换到其他版本,只需使用 nvm use <version> 命令。

0
看了该问题的人还看了