在Ubuntu上更新Node.js版本,您可以使用NodeSource存储库或NVM(Node Version Manager)。以下是两种方法的详细步骤:
sudo apt-get remove --purge nodejs
sudo apt-get autoremove
sudo apt-get update
sudo apt-get install curl software-properties-common
maverick
替换为你需要的Node.js版本代号。例如,如果你想安装最新的LTS版本,可以使用nodist
:curl -fsSL https://deb.nodesource.com/setup_maverick.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
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
或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts
node -v
npm -v
通过以上步骤,您可以轻松地在Ubuntu系统上更新Node.js版本。如果您想要切换到其他版本,只需使用nvm use version
命令即可。