在Debian环境下升级Node.js,你可以选择使用NodeSource存储库或者nvm(Node Version Manager)。下面是两种方法的详细步骤:
方法一:使用NodeSource存储库
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
方法二:使用nvm(Node Version Manager)
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
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" # This loads nvm
nvm install 14
nvm use 14
node -v
npm -v
现在,你已经成功地在Debian环境下升级了Node.js。如果你想要切换到其他版本,只需使用nvm use <version>
命令。