在Ubuntu上更新Node.js,常用方法有以下兩種:
sudo apt-get remove --purge nodejs
,sudo apt-get autoremove
。curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
(lts.x
可替換為具體版本號,如16.x
)。sudo apt-get install -y nodejs
。node -v
,npm -v
。curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
。source ~/.bashrc
。nvm install --lts
,或安裝特定版本如nvm install 16
。nvm use --lts
,設置默認版本可nvm alias default lts/*
。node -v
,npm -v
。