centos

Node.js 在 CentOS 上如何进行版本升级

小樊
63
2025-04-30 19:09:12
栏目: 编程语言

在 CentOS 上升级 Node.js 版本,你可以选择使用 NodeSource Repository 或者 NVM(Node Version Manager)

方法一:使用 NodeSource Repository

  1. 首先,删除已安装的 Node.js:
sudo yum remove nodejs
  1. 安装必要的开发工具:
sudo yum groupinstall "Development Tools"
  1. 安装 NodeSource Repository。以下命令将添加 Node.js 14.x 的源(你可以根据需要更改版本):
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
  1. 安装 Node.js:
sudo yum install nodejs
  1. 验证安装:
node -v
npm -v

方法二:使用 NVM(Node Version Manager)

  1. 首先,卸载已安装的 Node.js:
sudo yum remove nodejs
  1. 安装 NVM。运行以下命令以安装最新版本的 NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  1. 激活 NVM:
source ~/.bash_profile
  1. 使用 NVM 安装所需的 Node.js 版本。例如,要安装最新的 LTS(长期支持)版本,可以运行:
nvm install --lts
  1. 切换到新安装的 Node.js 版本:
nvm use --lts
  1. 验证安装:
node -v
npm -v

现在,你已经成功地在 CentOS 上升级了 Node.js 版本。如果你想切换到其他版本,只需使用 nvm use <version> 命令。

0
看了该问题的人还看了