centos

CentOS 环境 Node.js 怎么安装

小樊
91
2025-04-30 19:02:12
栏目: 编程语言

在 CentOS 系统中安装 Node.js,你可以选择使用包管理器(如 yum 或 dnf)或者使用 NodeSource 仓库

方法一:使用包管理器安装

  1. 首先,更新系统软件包:
sudo yum update

或者(CentOS 8 及以上版本)

sudo dnf update
  1. 安装 EPEL 软件仓库(如果尚未安装):
sudo yum install epel-release

或者(CentOS 8 及以上版本)

sudo dnf install epel-release
  1. 安装 Node.js:
sudo yum install nodejs

或者(CentOS 8 及以上版本)

sudo dnf install nodejs
  1. 安装 npm(Node.js 包管理器):
sudo yum install npm

或者(CentOS 8 及以上版本)

sudo dnf install npm

方法二:使用 NodeSource 仓库安装

  1. 首先,卸载已安装的 Node.js 和 npm(如果存在):
sudo yum remove nodejs npm

或者(CentOS 8 及以上版本)

sudo dnf remove nodejs npm
  1. 安装必要的软件包:
sudo yum install -y curl gcc-c++ make

或者(CentOS 8 及以上版本)

sudo dnf install -y curl gcc-c++ make
  1. 使用 NodeSource 仓库安装指定版本的 Node.js。例如,要安装最新的 LTS(长期支持)版本,可以运行:
curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
  1. 安装 Node.js:
sudo yum install -y nodejs

或者(CentOS 8 及以上版本)

sudo dnf install -y nodejs
  1. 验证安装结果:
node -v
npm -v

现在,你已经在 CentOS 系统中成功安装了 Node.js 和 npm。

0
看了该问题的人还看了