yarn command not found, or yarn global binaries not found
yarn: command not foundShort 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.
Fix it fast
1Find out which cause you have
Check whether yarn exists at all, and what npm installed globally.
command -v yarn npm ls -g --depth=02Match what you see, then jump to its fix
- 1
command -v yarn prints nothing, and yarn is missing from npm ls -g.Yarn was never installed in this Node.js environmentFix - 2
The project has a packageManager field or uses Yarn 2+, and yarn is not found.Corepack is not installed or not enabledFix - 3
yarn works, but a tool added with yarn global add is not found.The yarn global bin folder is not on PATHFix - 4
You use Yarn 2+ and yarn global fails or is not offered.yarn global does not exist in Yarn 2 and newerFix
- 1
What does the error look like?
yarn: command not foundzsh: command not found: yarnzsh: 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=02Fix
The Yarn Classic docs recommend installing through npm. Then check the version.
npm install --global yarn@1
yarn --version3Verify
yarn --version prints a version number.
yarn --versionConfirmed by classic.yarnpkg.com
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 --version2Fix
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 enable3Verify
Run yarn inside the project and see the version from packageManager.
yarn --versionConfirmed by github.com
Cause 3 of 4
The yarn global bin folder is not on PATH
1Check
Print where Yarn Classic puts its symlinks.
yarn global bin2Fix
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
Cause 4 of 4
yarn global does not exist in Yarn 2 and newer
1Check
Check the Yarn version used in the project.
yarn --version2Fix
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> --versionConfirmed by yarnpkg.com
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
The nest command is not found in the terminal
bash: nest: command not found
The shell cannot find a nest executable on its PATH.
3 causes, each with a fixBack 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 fixBack end
node and npm vanish or are not found when nvm is installed
nvm current prints system in a new shell
nvm adds node and npm to PATH only for the version it has activated.
4 causes, each with a fixBack end
The serverless command is not found in the shell
bash: serverless: command not found
The shell can only run serverless if it is installed globally and the folder npm links global commands into is on PATH.
3 causes, each with a fixBack 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 fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fix