How to install yarn on Ubuntu 20.04 – quick‑start guide
If you’re trying to get a React or Vue project running faster, the first thing you’ll need is Yarn on Ubuntu 20.04. This post walks through three common ways: using apt with the official Yarn repo, installing via npm from Node LTS, and leveraging nvm for per‑project versions. It covers why each step matters so you can skip the guesswork.
Why use Yarn instead of npm?
Yarn was created to solve npm’s latency and nondeterministic installs back in 2016. Most of us have hit that “package lockfile is out of sync” headache after a quick npm install. With Yarn, deterministic resolutions keep your CI runs predictable and the download speeds are usually faster thanks to caching.
install yarn on Ubuntu 20.04 via the official repo
The safest route if you don’t mind keeping Yarn up‑to‑date with the system package manager is adding Docker’s maintained repository:
1. Add the GPG key
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
This guarantees your packages come from Yarn’s own signing key, preventing a rogue package.
2. Register the Yarn repository
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Without this line, apt will look in Ubuntu’s default repos that ship an older Yarn version.
3. Refresh and install
sudo apt update && sudo apt install yarn
Updating the package index ensures you’re pulling the latest repo data before installing.
You’ve now got a globally available yarn binary that works out of the box with any Node version installed via apt or nvm. If you later need a newer Yarn release, just run sudo apt upgrade yarn.
Install yarn on Ubuntu 20.04 using npm (Node LTS)
If you already have Node LTS from the official Ubuntu repo (nodejs package) and don’t want to touch your system packages, Yarn can be installed through npm:
sudo npm install -g yarn
This method bundles Yarn with npm itself, so it follows whatever Node version you’re using. However, the version of Yarn that ships via npm is often a couple releases behind the official repo.
Install yarn on Ubuntu 20.04 with nvm (per‑project isolation)
For developers juggling multiple projects that need different Node/Yarn combos, nvm is a lifesaver:
1. Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash source ~/.bashrc
nvm lets you switch Node versions without touching system files.
2. Install a Node LTS (if you don’t already have one)
nvm install --lts
3. Add Yarn to the node module bin folder
npm i -g yarn
4. Verify
yarn --version
By installing Yarn inside the Node environment nvm manages, you keep it isolated from other projects that might need a different Yarn major version.
Common pitfall: PATH not updated after a fresh install
I’ve seen this happen when someone installs Yarn via npm and then opens a new terminal. The yarn command isn’t found until they close the session or source their profile again:
source ~/.profile # or ~/.bashrc, depends on your shell
Make sure your $PATH includes the directory where global npm binaries live (~/.npm-global/bin or /usr/local/bin). If it’s missing, Yarn won’t run no matter how many times you install it.
Quick sanity check
Run yarn --version. It should output a number like 1.22.19. Then try installing a package:
mkdir test-yarn && cd $_ npm init -y # create a minimal package.json yarn add react
If the command finishes without errors, Yarn is ready to go.
That’s all there is to it. Pick the method that fits your workflow and you’ll be installing packages faster than a coffee break.