Using pnpm to manage Node versions

Supplement

Only pnpm installed via the standard script can manage Node.js versions.

curl -fsSL https://get.pnpm.io/install.sh | sh -

Otherwise, you’ll get an error:

❯ pnpm env add --global 25
 ERR_PNPM_CANNOT_MANAGE_NODE  Unable to manage Node.js because pnpm was not installed using the standalone installation script

Original Article

Translated by SimpRead, original URL allenmrbai.github.io

In daily work, we often need to use different Node.js versions across various projects. pnpm provides a very convenient command pnpm env use <node-version> to switch Node.js versions, allowing us to easily switch between different Node.js versions for different projects—eliminating the need to install nvm separately.

[#installing-pnpm “Installing pnpm”] Installing pnpm

Note: If you install pnpm using npm i -g pnpm, the pnpm env use command will not be available. You must install pnpm using one of the following methods (if you’ve already installed nvm, refer to this link to remove nvm before installing pnpm):

[#installing-pnpm-on-windows “Installing pnpm on Windows”] Installing pnpm on Windows

Using PowerShell:

Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression

Official documentation

[#on-posix-systems “On POSIX Systems”] On POSIX Systems

curl -fsSL https://get.pnpm.io/install.sh | sh -

If curl is not installed, you can use wget instead:

wget -qO- https://get.pnpm.io/install.sh | sh -

Official documentation

[#usage “Usage”] Usage

After installation, restart your terminal (or run source ~/.bashrc or source ~/.zshrc or source ~/.bash_profile to apply the changes). Then run pnpm -v to verify the version.

To switch Node.js to version 22, run:

pnpm env use --global 22

node -v # v22.15.0

To switch Node.js to version 16:

pnpm env use --global 16

node -v # v16.20.2

Here’s a handy tip: if a project requires pnpm version 8 and Node.js version 16, you can run:

pnpm env use --global 16

npx pnpm@8 install