在 Ubuntu 上安装 Node.js 稳定版(LTS),推荐用 NodeSource 官方源 或 nvm,下面给你两种常用方式。
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
如果想装 18.x,把
20.x改成18.x
sudo apt install -y nodejs
node -v
npm -v
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts
nvm alias default lts/*
node -v
npm -v
如果你告诉我:
我可以给你更精确的安装命令。