
How to Fix “bash: yarn: command not found” on Linux
If you’re working on a Node.js project and suddenly hit the error:
bash: yarn: command not found
Don’t worry — this is a common issue, especially when switching environments, reinstalling systems, or working on new Linux setups.
In this guide, we’ll explain why this error occurs, how to fix it step by step, and share some tips for managing Yarn more effectively on Linux.
🧠 Why You’re Seeing “bash: yarn: command not found”
This error means that Yarn isn’t installed or the Yarn binary isn’t in your system’s PATH. The bash
shell can’t find the yarn
command to execute it.
Common Reasons:
- Yarn was never installed.
- Yarn was installed using an unsupported method.
- You recently removed Node.js or switched to a new shell or user.
- The PATH environment variable is misconfigured.
🔧 Step-by-Step Fixes
Let’s go through the possible solutions depending on your system setup.
✅ 1. Check if Yarn is Installed
Run:
which yarn
If the output is empty, it means yarn
is not found in your $PATH
.
You can also try:
yarn --version
If this returns the same error (command not found
), move on to installation.
✅ 2. Install Yarn (Recommended Method)
Use the official Yarn installation via Corepack (bundled with Node.js ≥16.10):
Step A: Check if Corepack is available
corepack enable
Then install Yarn:
corepack prepare yarn@stable --activate
Test the installation:
yarn --version
⚠️ If you get
corepack: command not found
, update your Node.js version to ≥16.10 or try a different method below.
✅ 3. Install Yarn via npm (Alternate Method)
You can install Yarn globally using npm:
npm install --global yarn
Then verify:
yarn --version
📝 This works only if
npm
andnode
are already correctly installed.
✅ 4. Add Yarn to PATH (If Already Installed)
Sometimes Yarn is installed, but not added to your system’s PATH
.
Step A: Find Yarn Location
Try:
find / -name yarn -type f 2>/dev/null
If you locate the binary (e.g., /home/user/.yarn/bin/yarn
), add it to your .bashrc
:
echo 'export PATH="$PATH:/home/user/.yarn/bin"' >> ~/.bashrc
source ~/.bashrc
Then try:
yarn --version
✅ 5. Install Yarn via Package Manager (For Ubuntu/Debian)
Yarn has an official APT repository:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
❗ If you get an error related to Node.js, install it first:
sudo apt install nodejs
🧪 Test Your Yarn Setup
After installation, test with:
yarn --version
And try creating a new project:
yarn init -y
If it succeeds, your setup is working!
🛠️ Bonus Tips
- Use nvm (Node Version Manager) to manage multiple Node versions cleanly. It also helps avoid conflicts with Yarn and npm.
- Regularly run
yarn set version stable
to keep Yarn up to date. - Avoid installing Yarn with
apt install yarn
on Ubuntu without the official Yarn repo — it may install a different package (like cmdtest).
🧯 Still Seeing the Error?
If none of the solutions worked:
- Double-check shell config files like
.bashrc
,.zshrc
, or.profile
. - Restart your terminal or system to reload PATH changes.
- Confirm that
node
andnpm
are installed and working:node -v npm -v
✅ Final Thoughts
The “bash: yarn: command not found
” error on Linux usually boils down to one of two things: Yarn isn’t installed, or it’s installed but not accessible from your shell.
By following the steps above, you should be able to fix the issue quickly and get back to work on your Node.js or front-end project.
📣 Found This Helpful?
Bookmark this guide or share it with your developer friends who might face the same problem. For more Linux tips, error fixes, and dev tool guides — check out our latest posts!