温馨提示×

centos如何更新nodejs到最新版

小樊
53
2025-08-22 16:47:47
栏目: 编程语言

CentOS更新Node.js到最新版主要有以下两种方法:

  • 使用NodeSource仓库
    1. 移除旧版本(可选):sudo yum remove nodejs
    2. 添加NodeSource仓库:curl -sL https://rpm.nodesource.com/setup_current.x | sudo bash -(安装最新版)或curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -(安装LTS版)。
    3. 安装Node.js:sudo yum install -y nodejs
    4. 验证:node -v
  • 使用NVM(Node Version Manager)
    1. 安装NVM:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    2. 重新加载环境变量:source ~/.bashrc
    3. 列出可用版本:nvm ls-remote
    4. 安装最新版:nvm install node(安装最新稳定版)或nvm install <版本号>(安装指定版本)。
    5. 切换版本(若安装了多个):nvm use <版本号>,设置默认版本:nvm alias default <版本号>
    6. 验证:node -v

0