温馨提示×

centos如何升级nodejs版本

小樊
54
2025-08-20 16:40:39
栏目: 编程语言

CentOS升级Node.js版本主要有以下两种方法:

  • 使用NodeSource仓库
    1. 卸载已有的Node.js:sudo yum remove nodejs
    2. 安装必要软件包:sudo yum install -y curl gcc-c++ make
    3. 添加NodeSource仓库,如添加LTS版本仓库:curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
    4. 安装Node.js:sudo yum install -y nodejs
    5. 验证版本:node -v
  • 使用NVM(Node Version Manager)
    1. 卸载已有的Node.js:sudo yum remove nodejs
    2. 安装NVM:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
    3. 激活NVM:source ~/.bash_profilesource ~/.bashrc
    4. 安装所需Node.js版本,如安装LTS版本:nvm install --lts,或安装特定版本nvm install <version>
    5. 切换到所需版本:nvm use <version>
    6. 验证版本:node -v

0