温馨提示×

Node.js在Ubuntu上怎么配置环境

小樊
58
2025-03-26 20:07:59
栏目: 编程语言

在Ubuntu上配置Node.js环境可以通过以下几种方法:

使用NodeSource PPA安装Node.js

  1. 添加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版本号,可以根据需要更改。

  1. 安装Node.js和npm
sudo apt install nodejs 
  1. 验证安装
node -v npm -v 

使用NVM(Node Version Manager)安装Node.js

  1. 安装NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash 
  1. 激活NVM
source ~/.bashrc 
  1. 安装特定版本的Node.js
nvm install 16.14.0 
  1. 验证安装
node -v npm -v 

使用Ubuntu默认仓库安装Node.js

  1. 更新系统软件包列表
sudo apt update 
  1. 安装Node.js和npm
sudo apt install nodejs npm 
  1. 验证安装
node -v npm -v 

0