在Ubuntu上更新Node.js,推薦使用NodeSource存儲庫或NVM(Node Version Manager),具體方法如下:
sudo apt-get remove --purge nodejs
,sudo apt-get autoremove
。sudo apt-get update
。curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
(可替換為所需版本)。sudo apt-get install -y nodejs
。node --version
,npm --version
。curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
。source ~/.bashrc
。nvm list-remote
。nvm install --lts
。nvm use --lts
。node --version
,npm --version
。