FedoraRHEL Based

How To Install Yarn on Fedora 40

Install Yarn on Fedora 40

In this tutorial, we will show you how to install Yarn on Fedora 40. Yarn, short for “Yet Another Resource Negotiator,” is a package manager for JavaScript that was initially developed by Facebook in collaboration with Exponent, Google, and Tilde. It was created to address some of the shortcomings of npm, the default package manager for Node.js.

Yarn is a fast, reliable, and secure alternative to npm. It uses a deterministic algorithm to ensure that package installations are consistent across different machines and environments. This consistency is crucial for maintaining reproducible builds and avoiding the “works on my machine” syndrome.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Yarn on Fedora 40.

Prerequisites

Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • A server running one of the following operating systems: Fedora 40.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
  • A stable internet connection to download the necessary packages.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Yarn on Fedora 40

Step 1. Update the System.

To ensure a successful installation of the Inkscape, it’s crucial to update your Fedora 40 system to the latest available version. Updating your system not only provides you with the latest security patches and bug fixes but also ensures that you have access to the most recent packages required for the installation. To update your Fedora 40 system, open the terminal and run the following command:

sudo dnf clean all
sudo dnf update

This command will fetch the latest package information and install any available updates for your Fedora 40 system.

Step 2. Installing Node.js.

To install Node.js on Fedora 40, you can use the official NodeSource repository. Run the following commands:

sudo dnf install nodejs

Step 3. Installing Yarn on Fedora 40.

There are several methods to install Yarn on Fedora 40. We’ll cover four main approaches, each with its own advantages and use cases.

  • Method 1: Using DNF Package Manager

The DNF package manager is the preferred method for installing software on Fedora. To install Yarn using DNF, follow these steps:

sudo dnf config-manager --add-repo https://dl.yarnpkg.com/rpm/yarn.repo

Install Yarn:

sudo dnf install yarn

Verify the installation:

yarn --version
  • Method 2: Using NPM

If you prefer to use npm to manage your Node.js tools, you can install Yarn globally using npm:

sudo npm install -g yarn

Verify the installation:

yarn --version

This method is convenient if you’re already familiar with npm and want to keep your Node.js tools managed in one place.

  • Method 3: Manual Installation via Tarball

For more control over the installation process, you can manually install Yarn using a tarball:

curl -O https://yarnpkg.com/latest.tar.gz

Extract the tarball:

tar zvxf latest.tar.gz

Move the extracted folder to a suitable location:

sudo mv yarn-* /opt/yarn

Add Yarn to your PATH by editing your ~/.bashrc file:

echo 'export PATH="$PATH:/opt/yarn/bin"' >> ~/.bashrc
source ~/.bashrc

Verify the installation:

yarn --version

This method gives you more control over where Yarn is installed and allows for easy version management.

  • Method 4: Using Installation Script

Yarn provides a convenient installation script that automates the process:

curl -o- -L https://yarnpkg.com/install.sh | bash

Verify the installation:

yarn --version

This method is quick and easy, but may require you to restart your terminal or source your shell configuration file after installation.

Step 3. Configuring Yarn

After installing Yarn, you may want to configure it to suit your development needs.

  • Setting up Yarn’s global directory

By default, Yarn installs global packages in a directory within your home folder. You can change this by running:

yarn config set prefix ~/.yarn-global
  • Configuring Yarn’s PATH

To ensure that globally installed packages are accessible, add the following to your ~/.bashrc file:

export PATH="$PATH:$(yarn global bin)"

Step 4. Basic Yarn Commands and Usage

Now that Yarn is installed and configured, let’s explore some basic commands to get you started.

  • Initializing a new project

To start a new project with Yarn, run:

yarn init
  • Adding dependencies

To add a dependency to your project:

yarn add [package-name]

For development dependencies:

yarn add [package-name] --dev
  • Removing packages

To remove a package:

yarn remove [package-name]
  • Upgrading packages

To upgrade a package:

yarn upgrade [package-name]

To upgrade all packages:

yarn upgrade

Congratulations! You have successfully installed Yarn. Thanks for using this tutorial for installing the Yarn on Fedora 40 system. For additional help or useful information, we recommend you check the official Yarn website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button