在Debian中管理Node.js版本,你可以使用NodeSource存储库或者nvm(Node Version Manager)
方法1:使用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
方法2:使用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
~/.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" # This loads nvm
然后运行source ~/.bashrc
(或相应的配置文件)以激活nvm。
nvm install --lts
nvm use <version>
将<version>
替换为你需要的版本,例如14.17.0
。
node --version
npm --version
现在你已经成功地在Debian中管理了Node.js版本。你可以随时切换到其他版本,而无需重新安装。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Node.js版本如何在Debian选择