debian

Debian如何更新Node.js版本

小樊
33
2025-02-25 23:18:56
栏目: 编程语言

要在Debian上更新Node.js版本,您可以使用NodeSource存储库或NVM(Node Version Manager)。这里是两种方法的详细说明:

方法1:使用NodeSource存储库

  1. 首先,删除已安装的Node.js(如果有的话):
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
  1. 更新系统包列表:
sudo apt-get update
  1. 安装NodeSource存储库。以下命令将添加Node.js 14.x存储库(您可以选择其他版本,例如12.x、16.x等):
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  1. 安装Node.js和npm:
sudo apt-get install -y nodejs
  1. 检查Node.js和npm是否已成功安装:
node -v
npm -v

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

  1. 首先,卸载已安装的Node.js(如果有的话):
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
  1. 安装依赖项:
sudo apt-get update
sudo apt-get install -y curl git build-essential libssl-dev
  1. 安装NVM。运行以下命令以在您的用户帐户下安装NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  1. 激活NVM:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
  1. 使用NVM安装最新版本的Node.js:
nvm install node
  1. 切换到新安装的Node.js版本:
nvm use node
  1. 检查Node.js和npm是否已成功安装:
node -v
npm -v

现在,您已经成功地在Debian上更新了Node.js版本。如果您想要切换到其他版本,只需使用nvm use <version>命令。

0
看了该问题的人还看了