温馨提示×

Node.js 在 Debian 上如何安装

小樊
43
2025-08-12 06:35:41
栏目: 编程语言

在 Debian 上安装 Node.js 的方法有多种,以下是其中两种常用的方法:

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

  1. 打开终端。

  2. 更新软件包列表:

sudo apt update
  1. 安装 Node.js 和 npm(Node.js 包管理器):
sudo apt install nodejs npm
  1. 检查 Node.js 和 npm 是否已成功安装:
node --version
npm --version

方法二:使用 NodeSource 仓库

  1. 打开终端。

  2. 安装必要的软件包以添加 NodeSource 仓库:

sudo apt install curl software-properties-common
  1. 添加 Node.js 仓库。以下命令将添加最新的 LTS(长期支持)版本的 Node.js 仓库:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
  1. 更新软件包列表:
sudo apt update
  1. 安装 Node.js 和 npm:
sudo apt install nodejs npm
  1. 检查 Node.js 和 npm 是否已成功安装:
node --version
npm --version

这两种方法都会在 Debian 系统上安装 Node.js 和 npm。使用包管理器安装的方法会安装一个较旧的版本,而使用 NodeSource 仓库的方法可以安装最新的 LTS 版本。根据你的需求选择合适的方法进行安装。

0