在Ubuntu上配置Node.js环境可以通过以下几种方法:
使用NodeSource PPA安装Node.js
- 添加NodeSource PPA:
sudo apt update sudo apt install curl -y curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
这里的16.x
是你想要安装的Node.js版本号,可以根据需要更改。
- 安装Node.js和npm:
sudo apt install nodejs
- 验证安装:
node -v npm -v
使用NVM(Node Version Manager)安装Node.js
- 安装NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
- 激活NVM:
source ~/.bashrc
- 安装特定版本的Node.js:
nvm install 16.14.0
- 验证安装:
node -v npm -v
使用Ubuntu默认仓库安装Node.js
- 更新系统软件包列表:
sudo apt update
- 安装Node.js和npm:
sudo apt install nodejs npm
- 验证安装:
node -v npm -v