在Debian上配置Node.js可以通过以下几种方法:
使用NodeSource存储库安装
- 更新包索引:
sudo apt update
- 安装必要的软件包:
sudo apt install curl build-essential
- 添加NodeSource存储库:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
- 安装Node.js和npm:
sudo apt install nodejs
- 验证安装:
node -v npm -v
使用NVM(Node Version Manager)安装
- 安装NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
- 加载NVM:
source ~/.bashrc
- 列出可用的Node.js版本:
nvm ls-remote
- 安装特定版本的Node.js:
nvm install 14.17.0
- 验证安装:
node -v npm -v
通过源码编译安装
- 下载源码:
git clone https://github.com/nodejs/node.git cd node
- 修改目录权限:
chmod -R 755 node
- 编译和安装:
./configure make sudo make install
- 验证安装:
node -v npm -v
这些方法可以帮助你在Debian系统上成功配置Node.js及其相关环境。