debian

Debian 系统如何更新 Node.js 版本

小樊
62
2025-08-12 06:44:42
栏目: 编程语言

在 Debian 系统中更新 Node.js 版本,你可以选择使用包管理器(如 apt)或者使用 NodeSource 仓库

方法一:使用包管理器(apt)

  1. 首先,更新你的系统包列表:
sudo apt update
  1. 然后,安装或更新 Node.js 和 npm:
sudo apt install nodejs npm
  1. 检查 Node.js 版本:
node --version
npm --version

请注意,使用 apt 安装的 Node.js 版本可能不是最新的。如果你需要最新版本,请考虑使用 NodeSource 仓库。

方法二:使用 NodeSource 仓库

  1. 首先,删除已安装的 Node.js(可选):
sudo apt-get purge nodejs npm
  1. 安装必要的软件包:
sudo apt-get install curl software-properties-common
  1. 添加 NodeSource 仓库。以下命令将添加最新的 LTS(长期支持)版本的 Node.js 仓库:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

如果你需要安装特定版本的 Node.js,可以将 setup_lts.x 替换为 setup_x.x,其中 x.x 是你需要的版本号。

  1. 更新系统包列表:
sudo apt update
  1. 安装 Node.js 和 npm:
sudo apt install nodejs npm
  1. 检查 Node.js 版本:
node --version
npm --version

现在,你已经成功更新了 Debian 系统上的 Node.js 版本。如果你需要切换到其他版本,只需重复上述步骤并添加相应版本的 NodeSource 仓库。

0
看了该问题的人还看了