centos

如何在centos上升级nodejs

小樊
40
2025-06-10 05:09:57
栏目: 编程语言

在 CentOS 上升级 Node.js 的推荐方法是使用 NodeSource 存储库

  1. 首先,删除现有的 Node.js:
sudo yum remove nodejs
  1. 安装必要的软件包以添加新的存储库:
sudo yum install -y curl
  1. 添加 NodeSource 存储库。以下命令将安装最新的 LTS(长期支持)版本的 Node.js。如果您需要其他版本,请将 lts/* 替换为所需的版本,例如 14.x16.x
curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
  1. 使用以下命令安装 Node.js:
sudo yum install -y nodejs
  1. 验证 Node.js 是否已成功安装以及其版本:
node --version
npm --version

现在,您已经在 CentOS 上升级了 Node.js。如果您需要更新到其他版本,只需重复上述步骤并更改 setup_lts.x 中的版本号。

0
看了该问题的人还看了