要在 CentOS 上升級 Node.js 版本,您可以使用 NodeSource 存儲庫或 NVM(Node Version Manager)。下面是使用這兩種方法的詳細步驟:
方法 1:使用 NodeSource 存儲庫
sudo yum remove nodejs
sudo yum install -y curl gcc-c++ make
lts/*
替換為所需的版本,例如 14.x
。curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs
node -v
方法 2:使用 NVM(Node Version Manager)
sudo yum remove nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bash_profile
或者
source ~/.bashrc
nvm install --lts
要安裝特定版本,請運行:
nvm install <version>
將 <version>
替換為您需要的版本,例如 14.x
。
nvm use <version>
將 <version>
替換為您需要的版本,例如 14.x
。
node -v
現在,您已經成功地在 CentOS 上升級了 Node.js 版本。如果您需要切換到其他版本,只需使用 nvm use <version>
命令。