在Debian系统下,您可以使用NodeSource存储库或者nvm(Node Version Manager)来管理Node.js版本。下面是两种方法的详细步骤:
方法一:使用NodeSource存储库
sudo apt-get remove --purge nodejs sudo apt-get autoremove sudo apt-get update sudo apt-get install curl software-properties-common curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get install -y nodejs node --version npm --version 方法二:使用nvm(Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash 或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash ~/.bashrc、~/.zshrc或~/.profile文件中: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" 然后运行:
source ~/.bashrc 或者,如果您使用的是zsh:
source ~/.zshrc nvm install 14 nvm use 14 node --version npm --version 使用nvm,您可以轻松地在不同版本的Node.js之间切换,以便根据项目需求进行开发。