安裝
必要條件#
pnpm 12 is a native executable and does not require Node.js after it is installed. The pnpm npm package installs on Node.js 18 or newer. The npx get-pnpm installer requires Node.js 22.13 or newer.
pnpm 12 is the current release line. The latest tag on npm points at it, so the commands below install pnpm 12 without naming a version.
Supported platforms#
pnpm 12 ships a prebuilt binary for each of these targets:
| Operating system | Architectures |
|---|---|
| Linux (glibc) | x64, arm64, riscv64, ppc64le, s390x, loong64 |
| Linux (musl) | x64, arm64 |
| macOS | arm64, x64 |
| Windows | x64, arm64 |
| FreeBSD | x64 |
| NetBSD | x64 |
| Android | arm64, x64 |
FreeBSD, ppc64le, s390x, RISC-V, and Android were added in v12.4.0. The NetBSD binary is built and tested on NetBSD 10. On a target with no binary, install the JavaScript pnpm 11 instead.
For StackBlitz WebContainers, see the experimental WebAssembly distribution.
Using pnpm#
If you already have pnpm v11.10.0 or newer, update directly to pnpm 12:
pnpm self-update
Inside a project that pins pnpm through the packageManager field, self-update only updates that pin instead of installing pnpm globally.
使用指令稿來安裝#
即使沒有安裝 Node.js,您還是可以透過下面提供的指令稿來安裝 pnpm。
Windows#
警告
當您使用此方式安裝 pnpm 時,有時 Windows Defender 可能會封鎖我們的可執行檔。
Due to this issue, we currently recommend installing pnpm using npm on Windows.
使用 Powershell:
Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression
On Windows, Microsoft Defender can slow down installation of packages. You can add pnpm to Microsoft Defender's list of excluded folders in a PowerShell window with administrator rights by executing:
Add-MpPreference -ExclusionPath $(pnpm store path)
POSIX 系統#
curl -fsSL https://get.pnpm.io/install.sh | sh -
如果沒有安裝 curl,您也可以改用 wget:
wget -qO- https://get.pnpm.io/install.sh | sh -
提示
You may use the pnpm runtime command then to install Node.js.
On Linux (kernel 5.9 or newer) with a LUKS2-encrypted NVMe SSD, dm-crypt queues reads and writes through kernel workqueues by default, which can slow down package installation. Find your crypt volume name with lsblk -o NAME,TYPE,MOUNTPOINTS, then bypass the workqueues and persist the setting in the LUKS2 header:
sudo cryptsetup refresh --perf-no_read_workqueue --perf-no_write_workqueue --persistent <crypt-volume-name>
在 Docker 容器中#
# bash
wget -qO- https://get.pnpm.io/install.sh | env ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
# sh
wget -qO- https://get.pnpm.io/install.sh | env ENV="$HOME/.shrc" SHELL="$(which sh)" sh -
# dash
wget -qO- https://get.pnpm.io/install.sh | env ENV="$HOME/.dashrc" SHELL="$(which dash)" dash -
安裝特定版本#
Before running the install script, you may optionally set an env variable PNPM_VERSION to install a specific version of pnpm:
curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=<version> sh -
Installing without changing PATH#
By default, the install scripts add pnpm to PATH through your shell configuration file, or on Windows, your user environment variables. To leave those unchanged, set PNPM_NO_MODIFY_PATH=1. pnpm is still installed in PNPM_HOME, and the installer prints the PNPM_HOME and PATH lines for you to add. This needs pnpm 12.16.0 or newer.
curl -fsSL https://get.pnpm.io/install.sh | env PNPM_NO_MODIFY_PATH=1 sh -
$env:PNPM_NO_MODIFY_PATH='1'; Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression
使用 npm 來安裝#
npx get-pnpm
Node.js 22.13 or newer is needed to run this installer, but not to run pnpm afterwards.
To install without changing PATH, run npx get-pnpm --no-modify-path. See Installing without changing PATH.
You can also install the pnpm package globally with npm, which needs Node.js 18 or newer:
npm install -g pnpm@latest
提示
您想在 CI 伺服器上使用 pnpm 嗎?請參閱持續整合 (Continuous Integration)。
相容性#
Here is a list of the supported pnpm versions with respective Node.js version support.
| Node.js | pnpm 10 | pnpm 11 | pnpm 12 |
|---|---|---|---|
| Node.js 18 | ✔️ | ❌ | ✔️ |
| Node.js 20 | ✔️ | ❌ | ✔️ |
| Node.js 22 | ✔️ | ✔️ | ✔️ |
| Node.js 24 | ✔️ | ✔️ | ✔️ |
| Node.js 26 | ✔️ | ✔️ | ✔️ |
pnpm 12 only needs Node.js when it is installed from npm; the version installed by the standalone script runs without Node.js.
疑難排解#
如果 pnpm 損毀且無法透過重新安裝來修復,您需手動將它移出 PATH。
For example, a leftover install of an older, JavaScript-based pnpm earlier on PATH can shadow pnpm 12 and fail like this when running pnpm install:
C:\src>pnpm install
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'C:\Users\Bence\AppData\Roaming\npm\pnpm-global\4\node_modules\pnpm\bin\pnpm.js'
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:725:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
首先,請嘗試執行 which npm 來尋找 pnpm 存放的位置。 If you're on Windows, run where.exe pnpm.*.
您將取得 pnpm 命令的位置,例如:
$ which pnpm
/c/Program Files/nodejs/pnpm
現在已經知道 pnpm CLI 存放的位置,請打開該資料夾並移除所有與 pnpm 有關的檔案(如 pnpm.cmd、pnpx.cmd、pnpm 等等)。完成後再重新安裝 pnpm,應該就恢復正常了。
更新 pnpm#
如要更新 pnpm,請執行 self-update 命令:
pnpm self-update
解除安裝 pnpm#
如果需要從系統中移除 pnpm 及其寫入磁碟的所有檔案,請參閱 [解除安裝 pnpm]。