Install and Use Yarn on AlmaLinux 8

In this article, we want to teach you how to Install and Use Yarn on AlmaLinux 8.

Yarn initially released by Facebook in 2016, is another popular package manager for the JavaScript programming language. The intention behind creating Yarn was to address some of the performance and security shortcomings of working with npm (at that time).

How To Install and Use Yarn on AlmaLinux 8

To install Yarn on AlmaLinux 8, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article about the Initial Server Setup with AlmaLinux 8.

Now follow the steps below to install Yarn.

Installing Yarn on AlmaLinux 8

First, update your local package index with the following command:

sudo dnf update

If Node.js is not installed on your server, you need to install it with the following command:

sudo dnf install @nodejs

Then verify your Node.js by checking its version with the following command:

node --version

In your output you will see:


Your Node.js version may be different from here.

Now you need to enable the Yarn repository and import the repository’s GPG key:

$curl --silent --location | sudo tee /etc/yum.repos.d/yarn.repo
$sudo rpm --import

When you have enabled the Yarn repository on AlmaLinux 8 you can install it with the following command:

sudo dnf install yarn

Verify your installation by checking the Yarn version:

yarn --version

In your output you will see:


You have now Yarn installed on your AlmaLinux 8, let’s see how to use it.

Using Yarn

At this point, we will show you how to use Yarn by creating a new project and adding/removing dependencies.

To create a new Yarn project, you can use the yarn init command.

Here we create a project named my_project, you can choose another name for it:

yarn init my_project

This command will ask you some questions. Press enter to accept the defaults or fill them with your answers.

This will look like this:

yarn init v1.22.15
question name (root): orca
question version (1.0.0): 0.0.1
question description: testing yarn
question entry point (index.js):
question repository url:
question author: olivia
question license (MIT):
question private:
success Saved package.json
Done in 107.06s.

This command will create a basic package.json file that contains the information you have provided.

You can modify this file any time you want.

Also, you can initiate a Yarn project in an existing directory on AlmaLinux 8. To do this, switch to the directory and run the following command:

yarn init

To add a package as a dependency to your project you can use the following command:

yarn add [package_name]

With this command, you can install the package and any packages that it depends on. Also, it will update the project’s package.json and yarn.lock files.

If you use only the package name in the command, Yarn will install it in the latest version.

To install a specific version or tag, use the following command:

yarn add [package_name]@[version_or_tag]

Also, you can upgrade the packages with the following commands:

$yarn upgrade
$yarn upgrade [package_name]
$yarn upgrade [package_name]@[version_or_tag]

If no package name is given, the command will update the project dependencies to their latest version according to the version range specified in the package.json file. Otherwise, only the specified packages are updated.

To remove a package from your project dependency you can use the Yarn remove command on AlmaLinux 8:

yarn remove [package_name]

This command will also update the project’s package.json and yarn.lock files.

In an existing project you can install all dependencies that are specified in the package.json file with the following command:


Or you can use:

yarn install


Yarn drew a lot of inspiration from npm, especially by using its shortcomings to create a package management solution that developers would love.

Hope you enjoy this article about installing and using Yarn on AlmaLinux 8.

May this article about Install and Use Yarn on Ubuntu 20.04 be useful for you.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!