Yarn is a fast, reliable dependency manager for JavaScript projects that caches every package it downloads and ensures consistent installations across machines. Whether you are building React applications, containerized microservices with Docker on Fedora, or managing repositories through GitHub Desktop on Fedora, Yarn streamlines package installation and dependency resolution. By the end of this guide, you will have a working Yarn installation on Fedora Linux, understand the differences between Yarn Classic and Modern Yarn, and know how to manage JavaScript dependencies effectively.
Choose Your Yarn Installation Method
Fedora offers several ways to install Yarn, each with different trade-offs. The table below summarizes your options:
| Method | Channel | Yarn Version | Updates | Best For |
|---|---|---|---|---|
| Fedora DNF | Fedora Repos | Classic (1.22.x) | Automatic via dnf upgrade | Most users who want simple, distro-integrated installation |
| Corepack | Official Yarn | Modern (4.x) or Classic | Manual via yarn set version | Developers who need per-project Yarn version control |
| NPM Global | npm registry | Classic (1.22.x) | Manual via npm update | Users already managing Node.js with NVM |
| Yarn Classic Repo | Yarn Classic | Classic (1.22.x) | Automatic via dnf upgrade | Users who prefer Yarn’s own package repository |
Choose DNF or the Yarn Classic Repository if you maintain existing projects or prefer system-integrated updates. For new development with monorepos or per-project version control, Corepack with Modern Yarn 4.x offers Plug’n’Play and faster dependency resolution. If you already use NVM to manage Node.js versions, installing Yarn via npm keeps everything in one workflow.
Yarn Classic (1.x) is in maintenance mode, while Modern Yarn (4.x) receives active development. Both remain fully functional, so your choice depends on project requirements rather than one being universally better.
Install Yarn on Fedora via DNF
Fedora’s official repositories include yarnpkg, which provides Yarn Classic. This method requires no third-party repositories and integrates with your existing package management workflow.
Update System Packages
First, refresh your package cache and apply any pending updates to ensure you start with a clean, up-to-date system:
sudo dnf upgrade --refresh
Install Yarn and Node.js
Next, install Yarn. The yarnpkg package depends on Node.js, so DNF installs both automatically:
sudo dnf install yarnpkg nodejs -y
Once the installation completes, verify that both Yarn and Node.js are accessible:
yarn --version
node --version
Expected output:
1.22.22 v22.20.0
These version numbers confirm that Yarn Classic and Node.js are ready to use. At this point, you can create JavaScript projects and manage dependencies with Yarn.
Install Modern Yarn via Corepack
Corepack is a Node.js tool for managing package manager versions on a per-project basis. This method installs Modern Yarn (version 4.x), which offers improved performance, better monorepo support, and the Plug’n’Play installation strategy.
Install Node.js and Enable Corepack
Fedora’s Node.js package does not include Corepack by default, so first install Node.js and Git (required for yarn init), then install Corepack globally via npm:
sudo dnf install nodejs git -y
sudo npm install -g corepack
Next, enable Corepack to activate the built-in Yarn and pnpm shims:
sudo corepack enable
Initialize a Project with Modern Yarn
Once Corepack is enabled, create a new project directory and initialize it with Yarn:
mkdir ~/my-project && cd ~/my-project
yarn init -2
The -2 flag initializes the project with Modern Yarn. As a result, Corepack downloads the appropriate Yarn version automatically on first use. Then, verify the installation:
yarn --version
Expected output for Modern Yarn:
4.12.0
With Corepack, each project specifies its Yarn version in
package.json. Different projects can use different Yarn versions without conflicts. See the official Yarn installation documentation for advanced configuration.
Install Yarn via NVM and NPM
Node Version Manager (NVM) lets you install and switch between multiple Node.js versions. In particular, this approach is useful for developers who work on projects requiring different Node.js versions. After installing Node.js through NVM, you can then install Yarn globally via npm.
Install NVM
First, download and run the official NVM installation script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
The script installs NVM to ~/.nvm and adds configuration to your shell profile. To activate NVM in your current session without opening a new terminal, run:
source ~/.bashrc
Alternatively, open a new terminal window for the changes to take effect automatically.
Install Node.js and Yarn
Once NVM is active, install the latest LTS (Long Term Support) version of Node.js:
nvm install --lts
Expected output showing the installation process:
Installing latest LTS version. Downloading and installing node v24.12.0... Downloading https://nodejs.org/dist/v24.12.0/node-v24.12.0-linux-x64.tar.gz... ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v24.12.0 (npm v11.6.2) Creating default alias: default -> lts/* (-> v24.12.0 *)
Next, install Yarn globally using npm:
npm install -g yarn
Finally, verify the installation:
yarn --version
Expected output:
1.22.22
When using NVM, Yarn is installed per Node.js version. If you switch to a different Node.js version with
nvm use, you may need to reinstall Yarn for that version. For more information about managing Node.js versions, see the NVM documentation on GitHub.
Install Yarn Classic via Yarn Repository
Alternatively, the Yarn team maintains their own RPM repository for Fedora, CentOS, and RHEL systems. This method provides Yarn Classic directly from the upstream source.
Add the Yarn Repository
First, ensure Node.js is installed on your system:
sudo dnf install nodejs -y
Next, add the Yarn Classic repository to your system:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
This command downloads the repository configuration and saves it to DNF’s repository directory. Additionally, the repository includes GPG key verification for package authenticity.
Install Yarn
With the repository configured, install Yarn using DNF:
sudo dnf install yarn -y
During the first installation, DNF imports the Yarn GPG key automatically. As a result, you will see output similar to:
Importing OpenPGP key 0x6963F07F: UserID : "Yarn RPM Packaging" Fingerprint: 9A6F73F34BEB74734D8C69149CBBB5586963F07F From : https://dl.yarnpkg.com/rpm/pubkey.gpg The key was successfully imported.
Then, verify the installation:
yarn --version
Expected output:
1.22.22
Configure Yarn
Once Yarn is installed, you can customize its behavior through configuration settings. These settings apply to Yarn Classic (1.x); in contrast, Modern Yarn uses a different configuration format stored in .yarnrc.yml files.
Set the Global Binary Path
When you install packages globally with yarn global add, Yarn places executable scripts in a global bin directory. To run these executables from anywhere, you need to add this directory to your system’s PATH.
Add the following line to your ~/.bashrc file:
echo 'export PATH="$PATH:$(yarn global bin)"' >> ~/.bashrc
To apply the changes immediately without opening a new terminal, run:
source ~/.bashrc
Alternatively, open a new terminal window for the changes to take effect automatically.
Configure Cache Location
Yarn caches downloaded packages to speed up future installations. By default, the cache is stored in your home directory. You can customize the location with:
yarn config set cache-folder ~/custom-yarn-cache
This command stores Yarn’s cache in ~/custom-yarn-cache instead of the default location. To view your current configuration settings, run:
yarn config list
Manage Packages with Yarn
Yarn provides intuitive commands for managing project dependencies. This section covers the essential operations you will use in daily development.
Create a New Project
To start a new JavaScript project, create a directory and initialize it with Yarn:
mkdir ~/my-app && cd ~/my-app
yarn init
During initialization, Yarn prompts you for project details (name, version, description, entry point) and then generates a package.json file. For a quick setup with default values, use yarn init -y instead.
Add Dependencies
Use yarn add to install packages. This command adds the package to your package.json and downloads it to node_modules:
yarn add lodash
For development-only dependencies (testing frameworks, build tools), use the --dev flag:
yarn add jest --dev
Similarly, to install a specific version of a package:
yarn add lodash@4.17.21
Update Dependencies
The yarn upgrade command updates packages to their latest versions within the version ranges specified in package.json:
yarn upgrade lodash
Alternatively, to update all packages in your project:
yarn upgrade
For more control, use interactive upgrades that show available versions and let you choose which packages to update:
yarn upgrade-interactive
Remove Dependencies
The yarn remove command uninstalls a package and removes it from package.json:
yarn remove lodash
Install All Dependencies
When you clone an existing project, use yarn install (or simply yarn) to install all dependencies listed in package.json:
yarn install
This command reads the yarn.lock file to install exact versions, thereby ensuring consistent installations across machines and environments.
Run Scripts
You can also define scripts in your package.json to automate common tasks:
{
"name": "my-app",
"scripts": {
"start": "node index.js",
"test": "jest",
"build": "webpack --mode production"
}
}
Then, run a script with yarn run followed by the script name:
yarn run start
Alternatively, for common script names like start, test, and build, you can omit run:
yarn start
yarn test
yarn build
Troubleshoot Yarn
This section addresses common issues you may encounter when using Yarn on Fedora.
Permission Denied When Installing Global Packages
If you encounter permission errors when running yarn global add, the global installation directory may be owned by root:
error An unexpected error occurred: "EACCES: permission denied, mkdir '/usr/local/share/.config'".
This error typically happens when Node.js was installed via sudo. First, check the current global directory:
yarn global dir
To resolve this, configure Yarn to use a user-owned directory instead:
yarn config set prefix ~/.yarn-global
echo 'export PATH="$PATH:$HOME/.yarn-global/bin"' >> ~/.bashrc
source ~/.bashrc
Dependency Conflicts
When different packages require incompatible versions of the same dependency, you may see warning messages during installation. In such cases, if a project requires a specific dependency version to resolve conflicts, add a resolutions field to your package.json:
{
"resolutions": {
"lodash": "4.17.21"
}
}
After adding resolutions, reinstall dependencies:
yarn install
Network Timeouts
Slow or unstable network connections can cause timeout errors:
error An unexpected error occurred: "https://registry.yarnpkg.com/package: ETIMEDOUT".
To fix this, increase the network timeout and retry the installation:
yarn config set network-timeout 300000
yarn install
Note that the value is in milliseconds; 300000 equals 5 minutes.
Clear Cache to Fix Installation Issues
Sometimes corrupted cache entries can cause installation failures. In that case, clear the cache and reinstall:
yarn cache clean
yarn install
Verbose Output for Debugging
For detailed logging that helps identify issues, add the --verbose flag to any Yarn command:
yarn install --verbose
As a result, this displays additional information about what Yarn is doing at each step.
Remove Yarn from Fedora
The complete removal instructions depend on how you installed Yarn. Follow the section below that matches your installation method.
Remove Yarn Installed via DNF
If you installed Yarn from Fedora’s repositories or the Yarn Classic repository:
sudo dnf remove yarnpkg -y
sudo dnf autoremove -y
Alternatively, if you used the Yarn repository package (named yarn instead of yarnpkg):
sudo dnf remove yarn -y
sudo dnf autoremove -y
Optionally, remove the Yarn repository if you added it:
sudo rm /etc/yum.repos.d/yarn.repo
Finally, verify removal by checking that Yarn is no longer available:
yarn --version
Expected output after successful removal:
bash: yarn: command not found
Remove Yarn Installed via NPM
If instead you installed Yarn globally through npm, use the following command:
npm uninstall -g yarn
Then, verify removal:
yarn --version
Expected output after removal:
bash: yarn: command not found
Remove Yarn User Data
The following commands permanently delete Yarn’s cache and global configuration. This does not affect your project-specific
node_modulesfolders orpackage.jsonfiles.
To remove Yarn’s cache and configuration files from your home directory:
rm -rf ~/.cache/yarn
rm -rf ~/.yarnrc
rm -rf ~/.yarn
Additionally, if you configured a custom global directory, remove it as well:
rm -rf ~/.yarn-global
Conclusion
You now have Yarn installed on Fedora Linux using the method best suited to your workflow. The DNF method provides simple, system-integrated package management, while Corepack offers per-project Yarn version control for teams that need consistency across environments. With Yarn configured, you can add dependencies, run scripts, and manage JavaScript projects efficiently. For a complete development environment, consider setting up Visual Studio Code on Fedora.