Skip to content

以下是在 Ubuntu 系统(包括 WSL 中的 Ubuntu)安装nodejs | npm | pnpm

准备

shell
sudo apt update

卸载冲突的 libnode-dev包 由于 libnode-dev是旧版 Node.js 的开发头文件,而你现在安装的是 Node.js 20.x,可以安全卸载它:

shell
sudo apt remove --purge libnode-dev
sudo apt install -f  # 修复依赖关系

1.安装node

获取最新版网站:https://deb.nodesource.com/

shell
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt-get install -y nodejs

2.安装npm

shell
sudo apt-get install npm

3.升级node版本

此命令代表升级当前最新稳定版

shell
sudo npm install npm@latest -g

4.安装pnpm

shell
npm install pnpm -g

镜像源

shell
# 国内 淘宝 镜像源
pnpm config set registry https://registry.npmmirror.com/
# 官方镜像源
pnpm config set registry https://registry.npmjs.org/