Troubleshooting

yarn or pnpm: command not found — enable them with Corepack or npm

yarn and pnpm do not ship with Node.js. Enable them with Corepack or install them with npm, and fix the Ubuntu cmdtest trap, Docker images and CI runners.

Published ~10 min read

yarn: command not found and pnpm: command not found mean the package manager is not installed. Node.js ships npm and nothing else. On Node.js 22 and 24, run corepack enable and both commands appear. Node.js 25 and later, including Node.js 26, no longer bundle Corepack, so install it first with npm install -g corepack, or install yarn or pnpm directly with npm.

quick fix
node --version              # Node.js has to be there first

# Node.js 22 or 24: Corepack is bundled
corepack enable              # sudo corepack enable if node lives in /usr/bin

# Node.js 25, 26 and later: Corepack is a separate package now
npm install -g corepack      # with sudo if node lives in /usr/bin
corepack enable

yarn --version
pnpm --version

If node itself is missing, fix that first with the Node.js install steps. If yarn runs but answers ERROR: There are no scenarios; must have at least one., you have a different program called yarn. That case is below.

Is Node.js installed at all?

Corepack and npm both need Node.js. Check what the shell can see before you install anything:

diagnose
command -v node npm corepack yarn pnpm   # prints a path for each one it finds
node --version
npm prefix -g                            # where global packages and their commands go
  • No node: install Node.js, ideally the current LTS from NodeSource or nvm rather than the old distribution package.
  • Node.js 22 or 24, corepack found: corepack enable is all you need.
  • Node.js 25 or newer, no corepack: this is expected. The Node.js project stopped shipping Corepack with version 25, so Node.js 26, the next LTS line, does not include it either.
  • yarn found, but it behaves strangely: check which program it is with command -v yarn. See the wrong yarn.

How do I enable yarn and pnpm with Corepack?

Corepack is a small tool from the Node.js project that manages package-manager versions. corepack enable places yarn, yarnpkg, pnpm and pnpx next to your node binary. The first time you run one of them, Corepack downloads the version the project asks for and caches it.

Corepack
corepack enable

# pin the package manager for this project
# (writes the "packageManager" field into package.json)
corepack use pnpm@latest
corepack use yarn@stable

The pin looks like "packageManager": "pnpm@9.15.9", usually with a hash after the version. Commit it. Every laptop and CI runner then uses that exact version. In a directory with no pin, yarn falls back to Yarn 1 (Classic) and pnpm to a current release.

“EACCES: permission denied, symlink”

corepack enable writes into the directory that holds node. With NodeSource or a distribution package that is /usr/bin, which belongs to root, so run sudo corepack enable. With nvm, Node.js lives in your home directory and sudo is neither needed nor helpful.

The download prompt in scripts

On first use Corepack prints ! Corepack is about to download https://registry.npmjs.org/… and, in an interactive terminal, asks Do you want to continue? [Y/n]. It does not ask when there is no terminal or when the CI variable is set. To silence the message completely, for example in a Dockerfile:

environment
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0

“Cannot find matching keyid”

Corepack verifies downloads against npm’s signing keys. Releases older than Corepack 0.31 do not know the keys npm switched to in early 2025, so they fail with Internal Error: Cannot find matching keyid. Update Corepack on its own with npm install -g corepack@latest, or update Node.js to a current point release.

“This project is configured to use pnpm”

Corepack refuses to run yarn in a project whose packageManager field says pnpm, and the other way round. Use the package manager the project names. If you really need the other one for a single command, COREPACK_ENABLE_STRICT=0 turns the check off.

Can I install yarn or pnpm with npm instead?

Yes. It is the simplest route when you want one global version on your own machine:

npm
npm install -g pnpm
npm install -g yarn       # Yarn 1 (Classic)

The yarn package on npm is Yarn 1, which is frozen. Yarn 2 and later are meant to be pinned per project, which is what corepack use yarn@stable does. Choose one route: if npm stops with npm error code EEXIST for bin/yarn or bin/pnpm, a global copy from the other route is in the way. Remove it with npm uninstall -g yarn pnpm before you install Corepack.

npm error code EACCES

When Node.js is installed system-wide, npm install -g writes into /usr/lib/node_modules and fails without root. On a server you administer, sudo npm install -g pnpm is fine. On a workstation, move npm’s global directory into your home instead:

user-level npm prefix
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc   # ~/.zshrc for zsh
source ~/.bashrc
npm install -g pnpm

nvm users never need this: nvm keeps every Node.js version and its global packages in ~/.nvm. Remember that global packages belong to one Node.js version, so after nvm install of a new version, yarn and pnpm have to be installed or enabled again.

Does pnpm have its own installer?

Yes. Current pnpm releases are a native executable, and the official script installs pnpm without needing Node.js at all:

Linux · macOS
curl -fsSL https://get.pnpm.io/install.sh | sh -
# without curl:
wget -qO- https://get.pnpm.io/install.sh | sh -

source ~/.bashrc       # or open a new terminal
pnpm --version

The script installs into PNPM_HOME (~/.local/share/pnpm on Linux, ~/Library/pnpm on macOS) and adds a short block to your shell profile that puts it on the PATH. If pnpm is still not found, that block landed in a profile your shell does not read. Run pnpm setup from the full path, or copy the block into ~/.zshrc yourself. Run the installer as your normal user, not with sudo: it only writes to your home directory. As with any script piped into a shell, on a machine that matters, save it first (curl -fsSL https://get.pnpm.io/install.sh -o pnpm-install.sh), read it, then run sh pnpm-install.sh.

Why does yarn say “There are no scenarios; must have at least one”?

Because it is not Yarn. Ubuntu 22.04 and 24.04 and Debian 12 carry a package called cmdtest, a scenario-testing tool that installs its own /usr/bin/yarn. When you type yarn on Ubuntu, the “Command not found” helper suggests sudo apt install cmdtest, because that is the package in the archive that ships /usr/bin/yarn. Install it and you get:

the wrong yarn
$ yarn
ERROR: There are no scenarios; must have at least one.
$ yarn install
ERROR: [Errno 2] No such file or directory: 'install'
Ubuntu · Debian 12
sudo apt remove cmdtest
hash -r                   # forget the old path
# then install the real yarn with Corepack or npm (above)

Debian 13 no longer carries cmdtest. Debian and Ubuntu also package Yarn itself as yarnpkg: Yarn 1 on Debian 12 and Ubuntu 22.04 and 24.04, Yarn 4 on Debian 13. In every release that package installs the command as yarnpkg, not yarn. So after apt install yarnpkg, yarn is still “not found”. Corepack or npm is the better choice anyway, because the distribution package pulls in the distribution’s own Node.js, which is often older.

How do I install yarn or pnpm on Alpine?

Alpine
apk add --no-cache nodejs npm
npm install -g pnpm        # or: npm install -g yarn

# Yarn 1 is also packaged in the community repository
apk add --no-cache yarn

On Alpine 3.22, the regular nodejs package does not include Corepack; only nodejs-current does. Installing through npm works on every Alpine release. Alpine 3.22 also packages pnpm in the community repository.

How do I install yarn or pnpm on macOS?

macOS · Homebrew
brew install pnpm
brew install yarn          # Yarn 1 (Classic)

# or Corepack, which Homebrew's current node formula does not include
brew install corepack

Homebrew treats the corepack formula as conflicting with yarn and pnpm, so pick one route. If you installed with npm and get zsh: command not found: yarn, npm’s global bin directory is not on the PATH that zsh reads. Add it to ~/.zshrc, as in the npm section, and open a new terminal.

How do I use yarn or pnpm in Docker?

The official node images used to make this invisible. Images for Node.js 25 and earlier contain Yarn 1, and those for Node.js 22 and 24 also contain Corepack. As of Node.js 26.0.0 the images ship neither. node:latest and node:26 point at 26, and node:lts moves to 26 when it becomes the LTS line (scheduled for 28 October 2026). A Dockerfile that used to build can therefore stop with /bin/sh: 1: yarn: not found or, from inside an npm script, sh: 1: pnpm: not found.

Dockerfile · Node.js 22 or 24
FROM node:24-slim
WORKDIR /app
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN corepack enable
COPY package.json pnpm-lock.yaml ./
RUN corepack install && pnpm install --frozen-lockfile
COPY . .
RUN pnpm run build
Dockerfile · Node.js 26 and later
FROM node:26-slim
WORKDIR /app
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN npm install -g corepack && corepack enable
COPY package.json pnpm-lock.yaml ./
RUN corepack install && pnpm install --frozen-lockfile
COPY . .
RUN pnpm run build

corepack install fetches the version pinned in package.json while the image is being built, so the container does not download it at runtime. It needs that packageManager pin and fails without one. For Yarn, copy yarn.lock and run yarn install --immutable (Yarn 2 and later) or yarn install --frozen-lockfile (Yarn 1). CI runners follow the same rule: enable Corepack in a step before the install step, and on Node.js 25 or later install it with npm first.

Why does Windows say “yarn.ps1 cannot be loaded”?

In PowerShell, an npm-installed yarn or pnpm can fail with File C:\Users\you\AppData\Roaming\npm\yarn.ps1 cannot be loaded because running scripts is disabled on this system. The command is installed. PowerShell’s execution policy blocks the wrapper script. Allow locally installed scripts for your own account:

PowerShell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

‘yarn’ is not recognized as an internal or external command is the plain “not installed or not on PATH” case: check that %AppData%\npm is in your user PATH. corepack enable needs a terminal opened as Administrator when Node.js is installed under C:\Program Files.

Installed, but still “command not found”?

  • npm’s global bin is not on PATH. On Linux and macOS the commands land in $(npm prefix -g)/bin. Compare that with echo $PATH.
  • pnpm complains about its global bin directory. ERR_PNPM_GLOBAL_BIN_DIR_NOT_IN_PATH (or ERR_PNPM_NO_GLOBAL_BIN_DIR in older releases) appears on pnpm add -g. Run pnpm setup, then open a new terminal.
  • The shell cached the old lookup. Run hash -r in bash or rehash in zsh.
  • It works for you, not under sudo. sudo resets PATH, so a yarn under ~/.nvm disappears. Avoid sudo for project commands, or install Node.js system-wide.
  • A script exits with code 127. That is the shell’s “command not found” status. The job runs in an environment without yarn or pnpm, often a new base image. See exit code 127.

Once the install itself works, the next error is usually about a project tool. sh: vite: not found after pnpm install is covered in vite: command not found, and a native dependency that cannot compile is covered in make: command not found. If the build dies with a bare Killed, the server ran out of memory: here is how to confirm and fix it. JavaScript builds lean on single-thread speed, which is what our Hi-CPU KVM line is built for.

Another tool missing, or a directory to add to PATH for good in bash, zsh and fish? See command not found: the three causes and the fix for every tool.

Frequently asked

Does Node.js include yarn?

No. Node.js ships npm and npx only. Node.js 22 and 24 also bundle Corepack, which turns on yarn and pnpm with 'corepack enable'; from Node.js 25 on, Corepack is a separate install ('npm install -g corepack'). The official Docker images added Yarn 1 up to Node.js 25, but the Node.js 26 images contain neither Yarn nor Corepack.

Corepack or npm install -g, which is better?

Corepack for projects: it reads the packageManager field in package.json, so every machine and CI runner uses the version the project pins. 'npm install -g pnpm' is fine for one global version on your own machine, but it ignores that pin, and the yarn package on npm is the frozen Yarn 1 line.

Why does yarn say 'There are no scenarios; must have at least one'?

You are running the yarn from Ubuntu's and Debian 12's cmdtest package, an unrelated testing tool that installs itself as /usr/bin/yarn. Remove it with 'sudo apt remove cmdtest', run 'hash -r', then install the real Yarn with Corepack or npm.

How do I use pnpm in Docker?

On node:22 and node:24 images, add 'RUN corepack enable' before the install step. Node.js 26 images ship without Corepack, so use 'RUN npm install -g corepack && corepack enable' or 'RUN npm install -g pnpm'. With a packageManager pin, 'corepack install' caches the pinned version in the image at build time.

Related articles

All troubleshooting