Share your love
How To Install Yarn on AlmaLinux 9
In this guide, we want to teach you How To Install and Use Yarn on AlmaLinux 9.
Yarn is a new package manager that replaces the existing workflow for the npm client or other package managers while remaining compatible with the npm registry. It has the same feature set as existing workflows while operating faster, more securely, and more reliably.
Steps To Install and Use Yarn on AlmaLinux 9
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 9.
Install Yarn Package Manager on AlmaLinux 9
First, update your local package index with the following command:
sudo dnf update
Installing Node.js
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 the following:
Output
v18.12.1
Your Node.js version may be different from here.
Add Yarn GPG Key and Repository
Now you need to enable the Yarn repository and import the repository’s GPG key on AlmaLinux 9 by using the following commands:
$ curl --silent --location 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
Rerun the system update:
sudo dnf update
Installing Yarn
When you have enabled the Yarn repository on AlmaLinux 9 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 the following:
Output
1.22.19
You have now Yarn installed on your AlmaLinux 9, let’s see how to use it.
How To Use Yarn on AlmaLinux 9
At this point, we will show you how to use Yarn by creating a new project and adding/removing dependencies.
Create a New Yarn Project
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:
Output
yarn init v1.22.19
question name (root): orca
question version (1.0.0):
question description: testing yarn
question entry point (index.js):
question repository url:
question author: reita
question license (MIT):
question private:
success Saved package.json
Done in 44.85s.
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 9. To do this, switch to the directory and run the following command:
yarn init
Add a Package with Yarn
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]
Upgrade a Package with Yarn
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.
Remove a Package with Yarn
To remove a package from your project dependency you can use the Yarn remove command on AlmaLinux 9:
yarn remove [package_name]
This command will also update the project’s package.json and yarn.lock files.
Install All Dependencies
In an existing project you can install all dependencies that are specified in the package.json file with the following command:
yarn
Or you can use:
yarn install
Conclusion
Yarn drew a lot of inspiration from npm, especially by using its shortcomings to create a package management solution that developers would love.
I hope you enjoy this guide on Install and Use Yarn on AlmaLinux 9.
You may be like these articles on the orcacore website:
Install and Use Yarn on Ubuntu 22.04