在 Debian 上安装 Node.js 的方法有很多种,这里介绍两种常用的方法:使用包管理器(APT)和使用 NodeSource 仓库
方法一:使用包管理器(APT)
打开终端。
首先更新软件包列表:
sudo apt update
sudo apt install nodejs npm
node --version
npm --version
方法二:使用 NodeSource 仓库
打开终端。
首先,根据需要选择要安装的 Node.js 版本。例如,要安装最新的 LTS(长期支持)版本,可以运行:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
如果要安装特定版本,例如 14.x,可以运行:
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node --version
npm --version
现在,您已经在 Debian 上成功安装了 Node.js 和 npm。可以开始使用它们来运行和部署您的 Node.js 应用了。