Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

yarn command not found, or yarn global binaries not found

Erroryarn: command not found

Short answer

The shell cannot find the yarn binary or a tool installed with yarn global. Install Yarn with npm install --global yarn@1 or Corepack, add the output of yarn global bin to PATH, and remember Yarn 2 and newer removed yarn global in favour of yarn dlx.

  • Applies to Node.js 22, npm 10, Yarn 1 and Yarn 4, Ubuntu 24.04, zsh and bash
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether yarn exists at all, and what npm installed globally.

    command -v yarn
    npm ls -g --depth=0
  2. 2Match what you see, then jump to its fix

    1. 1command -v yarn prints nothing, and yarn is missing from npm ls -g.Yarn was never installed in this Node.js environmentFix
    2. 2The project has a packageManager field or uses Yarn 2+, and yarn is not found.Corepack is not installed or not enabledFix
    3. 3yarn works, but a tool added with yarn global add is not found.The yarn global bin folder is not on PATHFix
    4. 4You use Yarn 2+ and yarn global fails or is not offered.yarn global does not exist in Yarn 2 and newerFix

What does the error look like?

  • yarn: command not found
  • zsh: command not found: yarn
  • zsh: command not found: <tool installed with yarn global add>

Cause 1 of 4

Yarn was never installed in this Node.js environment

1Check

A different Node.js version, or a version manager switch, can leave the global package behind.

node --version && npm ls -g --depth=0

2Fix

The Yarn Classic docs recommend installing through npm. Then check the version.

npm install --global yarn@1
yarn --version

3Verify

yarn --version prints a version number.

yarn --version

Confirmed by classic.yarnpkg.com

Did this fix it?

Cause 2 of 4

Corepack is not installed or not enabled

1Check

Corepack ships with Node.js from 14.19.0 up to but not including 25.0.0. Node.js 25 and later do not include it.

corepack --version

2Fix

On Node.js 25 or later, install Corepack with npm first. Uninstall a global Yarn first, then enable Corepack so the yarn shim lands on PATH.

npm install -g corepack
corepack enable

3Verify

Run yarn inside the project and see the version from packageManager.

yarn --version

Confirmed by github.com

Did this fix it?

Cause 3 of 4

The yarn global bin folder is not on PATH

1Check

Print where Yarn Classic puts its symlinks.

yarn global bin

2Fix

Add that folder to PATH in your shell profile (.bashrc or .zshrc), then open a new terminal.

# ~/.zshrc or ~/.bashrc
export PATH="$PATH:`yarn global bin`"

3Verify

The installed tool now resolves.

command -v <tool-name>

Confirmed by classic.yarnpkg.com

Did this fix it?

Cause 4 of 4

yarn global does not exist in Yarn 2 and newer

1Check

Check the Yarn version used in the project.

yarn --version

2Fix

The migration guide says yarn global was removed because system-wide package management is out of scope, and tells you to use yarn dlx to run one-off scripts.

yarn dlx <package-name>

3Verify

The tool runs without a global install.

yarn dlx <package-name> --version

Confirmed by yarnpkg.com

Did this fix it?

How do I stop it coming back?

  • Pin the package manager per project with Corepack and the packageManager field.
  • Put the PATH line in your shell profile once, not in a single session.
  • Do not install Yarn both globally and through Corepack.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm install worked but the command is not found

bash: vite: command not found

npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script.

3 causes, each with a fix

Back end

npm or a script fails in WSL with /usr/bin/env: 'bash\r'

/usr/bin/env: 'bash\r': No such file or directory

The \r in the message is a Windows line ending at the end of a script's first line, so Linux looks for a program called bash followed by a carriage return.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.