What Yarn is and why you need it
Yarn is a package manager that downloads and organizes code libraries your projects depend on. It works alongside Node.js — if you write JavaScript, Yarn handles fetching the right versions of those libraries, keeping them up to date, and making sure everyone on your team uses the same versions. Think of it as a librarian that keeps your project's dependencies organized and consistent.
You need Yarn installed before you can use it. The installation process is different depending on whether you're on Windows, Mac, or Linux, but all three routes take less than five minutes. After installation, you'll have a single command — yarn — available in your terminal or command prompt.
Key Takeaways
- Yarn requires Node.js to be installed first; check by typing node --version in your terminal.
- On Windows, the easiest route is the installer from the official Yarn website, which handles setup automatically.
- On Mac, Homebrew is the standard method and takes one command if you already have Homebrew installed.
- On Linux, your package manager (apt, yum, or dnf depending on your distribution) installs Yarn in one command.
- After installation, verify it worked by typing yarn --version in a new terminal window.
Install Node.js first
Yarn runs on top of Node.js, so you must have Node.js installed before Yarn will work. Open your terminal (Mac and Linux) or command prompt (Windows) and type this:
node --version
If you see a version number like v18.0.0 or higher, Node.js is already installed and you can skip to the next section. If you see "command not found" or "is not recognized", go to nodejs.org, download the LTS (Long Term Support) version, and run the installer. Restart your terminal after installation finishes.
Install Yarn on Windows
Go to yarnpkg.com and click the blue "Download" button. This downloads the Yarn installer for Windows. Open the downloaded file and follow the on-screen prompts — accept the license, choose an installation folder (the default is fine), and click Install. The installer handles everything automatically.
When the installer finishes, close it and open a new command prompt window. Type yarn --version to confirm the installation worked. You should see a version number like 1.22.19 or higher. If you see "command not found", restart your computer and try again — Windows sometimes needs a restart to recognize new programs.
Install Yarn on Mac
The easiest method on Mac is Homebrew, a package manager for Mac. If you already have Homebrew installed, open Terminal and type:
brew install yarn
Homebrew downloads and installs Yarn automatically. When it finishes, type yarn --version in the same Terminal window to confirm it worked.
If you don't have Homebrew installed, go to brew.sh and follow the installation instructions there first — it's a one-line command. After Homebrew is installed, come back and run the brew install yarn command above.
Install Yarn on Linux
The installation command depends on which Linux distribution you're using. Open a terminal and run the command that matches your system:
For Ubuntu or Debian: sudo apt update && sudo apt install yarn
For Fedora or RHEL: sudo dnf install yarn
For CentOS: sudo yum install yarn
If you're not sure which distribution you have, type cat /etc/os-release and look for the NAME field. After the installation finishes, type yarn --version to confirm it worked.
Verify the installation and start using Yarn
After installation on any system, open a new terminal or command prompt window and type yarn --version. You should see a version number. If you still see "command not found" or "is not recognized", close the terminal completely and open a fresh one — sometimes the terminal needs to reload its configuration.
Once Yarn is installed, you can use it in any project folder. Navigate to your project directory in the terminal and type yarn install to download the libraries listed in your project's package.json file. Yarn creates a yarn.lock file that records exactly which versions were installed, so everyone on your team gets the same setup.
Troubleshooting common installation problems
If Yarn installation fails on Windows, the most common cause is that Node.js is not installed or not in your system path. Run node --version again to confirm Node.js is there. If it is, restart your computer — Windows sometimes needs a restart to recognize new programs in the command prompt.
On Mac, if Homebrew installation fails, check that you have Homebrew installed by typing brew --version. If Homebrew is not there, install it from brew.sh first. If you see permission errors on Mac or Linux, you may need to use sudo before the install command, though this is usually not necessary with Homebrew.
On Linux, if you see "command not found" after installation, your package manager may not have Yarn in its repository. In that case, follow the alternative installation method on yarnpkg.com under "Installation" — you can install Yarn using npm (which comes with Node.js) by typing npm install --global yarn.
Frequently Asked Questions
Do I need both npm and Yarn?
No. npm comes with Node.js automatically, and Yarn is an alternative to npm. You can use either one for your projects. Many teams choose Yarn because it's faster and more consistent, but npm works fine too. You don't need both installed.
What's the difference between Yarn and npm?
Both download and manage code libraries, but Yarn is generally faster and creates a lock file that guarantees everyone uses the same versions. npm is built into Node.js and requires no separate installation. For most projects, either works — use whichever your team prefers.
Can I uninstall Yarn if I don't need it anymore?
Yes. On Windows, go to Control Panel, find Yarn in the installed programs list, and click Uninstall. On Mac, type brew uninstall yarn. On Linux, use sudo apt remove yarn (Ubuntu/Debian) or sudo dnf remove yarn (Fedora). Uninstalling Yarn does not affect Node.js or your projects.
Why does Yarn need Node.js?
Yarn is built on Node.js and uses its runtime to function. Node.js provides the underlying system that Yarn runs on. You can't use Yarn without Node.js, but you can use Node.js without Yarn — npm (which comes with Node.js) is the default package manager.
Is Yarn the same as Yarn 2 or Yarn 3?
Yarn 1 (also called "classic Yarn") is the standard version most projects use. Yarn 2 and Yarn 3 are newer versions with different features and are not compatible with older projects. When you install Yarn from the official site or your package manager, you get Yarn 1 by default, which is what most teams use.