安装
前言
If you don't use the standalone script or @pnpm/exe
to install pnpm, then you need to have Node.js (at least v18.12) to be installed on your system.
使用独立脚本安装
即使没有安装 Node.js,也可以使用以下脚本安装 pnpm。
Windows
使用 PowerShell:
Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression
在 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 env command then to install Node.js.
In a Docker container
# bash
wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
# sh
wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.shrc" SHELL="$(which sh)" sh -
# dash
wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.dashrc" SHELL="$(which dash)" dash -
安装特定版本
Prior to 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 -
使用 Corepack 安装
Since v16.13, Node.js is shipping Corepack for managing package managers. 这是一项实验性功能,因此您需要通过运行如下脚本来启用它:
If you have installed Node.js with pnpm env
Corepack won't be installed on your system, you will need to install it separately. See #4029.
corepack enable pnpm
如果您已经使用Homebrew安装了Node.js,您需要单独安装Corepack:
brew install corepack
这会自动将pnpm安装在您的系统上。
你可以通过下列命令固定项目所用的 pnpm 版本:
corepack use pnpm@latest
This will add a "packageManager"
field in your local package.json
which will instruct Corepack to always use a specific version on that project. 如果您想要可复现性,这可能很有用,因为所有使用 Corepack 的开发人员都将使用与您相同的版本。 当一个新版本的 pnpm 发布时,您可以重新运行上述命令。