How to Install Yarn on CentOS 8 (No More Node‑y Problems)
If you’re running a fresh CentOS 8 box and want to manage JavaScript packages with Yarn instead of npm, this guide will get you there without the usual headache of conflicting Node versions or missing GPG keys. I’ve been chasing a broken node_modules folder for months on a server that had an old Node release pulled from EPEL; installing Yarn the right way finally kept my build pipeline from crashing.
Make sure you have Node ≥ 14
Yarn expects a reasonably recent version of Node. On CentOS 8, the default repos ship Node 12, which is too old for many modern packages.
sudo dnf module list nodejs # see what’s available sudo dnf module enable nodejs:16 # pick the latest LTS sudo dnf install nodejs
If Yarn tries to run against a Node that can’t understand ES modules or newer syntax, you’ll end up with cryptic errors like “SyntaxError: Unexpected identifier.”
Add the official Yarn repository
Yarn’s team keeps an RPM repo that mirrors the npm registry. It also contains the GPG key so your system verifies the packages.
curl -sS https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
If you skip the key import, dnf will complain that it can’t verify the package’s authenticity. Worse, a man‑in‑the‑middle could drop a malicious RPM into the mix.
Install Yarn
sudo dnf install yarn
That’s all there is to it. After installation you should see something like:
Installed: yarn-1.22.19-1.x86_64 (@yarn)
Using the official repo keeps Yarn up‑to‑date with bug fixes, whereas manually pulling a tarball can leave you on an old version that might not play well with newer Node releases.
Verify the installation
yarn --version # should print something like 1.22.19
If it prints a number, congratulations—you’re ready to run yarn install in any project.
Optional: Add Yarn to your PATH for non‑root users
The RPM installs /usr/bin/yarn, which is already on the default PATH. If you’ve moved the binary somewhere else (e.g., a custom script), add it:
echo 'export PATH=$PATH:/opt/yarn/bin' >> ~/.bashrc source ~/.bashrc
What if yarn still complains?
Sometimes CentOS 8’s SELinux policy can bite. If you see “Permission denied” when trying to write to /var/lib/node_modules, try:
sudo setenforce 0 # temporarily disable SELinux
A restrictive SELinux context might stop Yarn from creating necessary directories.
TL;DR
1. Enable a recent Node module (nodejs:16 or higher).
2. Import Yarn’s RPM repo and GPG key.
3. sudo dnf install yarn.
4. Check with yarn --version.
That’s all you need to get Yarn running on CentOS 8 without the typical “I can’t find node” or “Yarn is not recognized” problems.