简单介绍如何在Linux上使用Node二进制包安装Node。

环境说明

  • 操作系统:Debian 13 Trixie (Linux)
  • 架构:amd64 (x86_64)
  • 安装版本:Node.js 22.14.0

安装步骤

1. 下载 Node.js 二进制包

bash
1
wget https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz -O /tmp/node-v22-linux-x64.tar.xz

或使用 curl:

bash
1
curl -L -o /tmp/node-v22-linux-x64.tar.xz https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz

2. 安装 Node.js

bash
12345
# 解压到 /usr/local 目录
tar -C /usr/local --strip-components=1 -xJf /tmp/node-v22-linux-x64.tar.xz

# 删除下载包
rm /tmp/node-v22-linux-x64.tar.xz

3. 验证安装

bash
12345
# 验证 Node.js 版本
node --version

# 验证 npm 版本
npm --version

4. 换源(可选,国内加速)

bash
1
npm config set registry https://registry.npmmirror.com

5. 验证换源

bash
1
npm config get registry

6. 测试下载 npm 包

bash
12
cd ~
npm install express --save

下载成功说明镜像源正常工作。

7. 清理测试文件

bash
1
rm -rf ~/node_modules ~/package.json ~/package-lock.json

常用命令

命令 说明
node --version 查看 Node.js 版本
npm --version 查看 npm 版本
npm install <package> 安装 npm 包
npm config get registry 查看当前镜像源
npm config set registry <url> 设置镜像源

卸载 Node.js

bash
1
rm -rf /usr/local/lib/node_modules /usr/local/bin/node /usr/local/bin/npm