49 lines
1.1 KiB
Markdown
49 lines
1.1 KiB
Markdown
## 安装nodejs22+环境
|
||
### 使用使用 NodeSource
|
||
首先,添加 NodeSource 的 PPA(个人包存档)
|
||
```shell
|
||
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
||
```
|
||
然后安装nodejs
|
||
```shell
|
||
apt-get install -y nodejs
|
||
```
|
||
### 使用n管理器
|
||
如果你想使用 n 管理器安装最新版本,可以先安装 n
|
||
```shell
|
||
npm install -g n
|
||
```
|
||
然后使用 n 安装 Node.js 22
|
||
```shell
|
||
n 22
|
||
```
|
||
### 验证安装
|
||
安装完成后,可以通过以下命令验证 Node.js 是否安装成功
|
||
```shell
|
||
node -v
|
||
```
|
||
## 安装pnpm
|
||
### 若已安装npm
|
||
版本不确定
|
||
```shell
|
||
npm install -g pnpm
|
||
```
|
||
### 使用独立脚本安装(不用安装nodejs)
|
||
Windows PowerShell
|
||
```shell
|
||
Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression
|
||
```
|
||
在POSIX系统上
|
||
```shell
|
||
curl -fsSL https://get.pnpm.io/install.sh | sh -
|
||
# 或者使用
|
||
# wget -qO- https://get.pnpm.io/install.sh | sh -
|
||
```
|
||
安装特定的版本
|
||
在运行安装脚本之前,你可以选择设置环境变量 PNPM_VERSION 来安装特定版本的 pnpm
|
||
```shell
|
||
curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=<version> sh -
|
||
```
|
||
|
||
|