How to install Yarn on an Ubuntu 22.04 VPS or Dedicated Server

How to install Yarn on an Ubuntu 22.04 VPS or Dedicated Server

Introduction

Yarn is a fast, secure, and reliable dependency manager designed to resolve some of the shortcomings exhibited by npm. The application relies on npm registry modules and is not a replacement for the npm. It caches all the packages it downloads and parallelizes operations to boost resource utilization to expedite install times. This tutorial will show you how to install and use Yarn on Ubuntu 22.04 VPS or Dedicated server through the APT package manager. This repository is updated consistently and avails the most recent Yarn’s version.

Before You Begin

For this tutorial to run flawlessly requires a fully configured Ubuntu 22.04 at a good VPS hosting or dedicated server hosting service.

Method 01: Installing Yarn from Ubuntu apt repository

The first thing when installing Yarn on Ubuntu 22.04 is adding a Yarn repository together with the signing key the repository. Issue the commands below:

$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

screenshot of Install Yarn on an Ubuntu

$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

screenshot of Install Yarn on an Ubuntu

Next, run the following commands to update your system and deploy Yarn on your system:

$ sudo apt-get update

screenshot of Install Yarn on an Ubuntu

$ sudo apt install yarn

screenshot of Install Yarn on an Ubuntu

The command above will automatically install Yarn if you have not installed Node.js on your server. However, if you are using the Node.js Version Manager, run the command below to skip the installation of Node.js:

$ sudo apt install--no-install-recommends yarn

Next, execute the command below to check the Yarn’s version:

$ sudo yarn --version

This will give you an output similar to the one below:

screenshot of Install Yarn on an Ubuntu

Method 2: Install latest version of Yarn on Ubuntu 22.04

To install the latest version of yarn, download the ‘Yarn’ tarball by writing out the following command in the Ubuntu 22.04 terminal:

For installing npm package:

$ sudo apt install npm

screenshot of Install Yarn on an Ubuntu

Now, download and install yarn:

Method 2: Install latest version of Yarn on Ubuntu 22.04

As we can see in the above screenshot, yarn latest version 1.22.19 has been installed on this system.

Step 2 – Using Yarn

By now you have deployed Yarn on your system, next you need to explore the most commonly used commands for Yarn:

Creating Projects

To generate a Yarn project execute the command below:

$ sudo yarn init my_yarn_project

The above init command will prompt you to answer several questions. Answer the questions accordingly or hit ENTER to skip them.

screenshot of Install Yarn on an Ubuntu

Once you answer all the question, Yarn will generate a new package.json file featuring the details you provided. The file is readily available and can be opened and edited at any time.

Adding Dependencies

The yarn add is a command used to add a new package to dependencies of a project. The command used to add the package takes the form:

$ sudo yarn add [package_name]

For example, here we are installing ‘react’ package using yarn:

$ sudo yarn add react

screenshot of Install Yarn on an Ubuntu

This command will update the yarn.lock and package.json files. Updating these files enables everyone working on the project to get similar dependencies when using yarn. Besides, you can use the yarn add command and specify the version or tag for the package you want to add:

$ sudo yarn add [package_name]@[version_or_tag]

Upgrading The Dependencies

If you want to use the latest version of a specific package, you can execute the command below:

$ sudo yarn upgrade [package_name]

Alternatively, if you want to upgrade the dependency to a specific version or tag, issue the command below:

$ sudo yarn upgrade [package_name]@[version_or_tag]

Removing A Dependency

If you want to expunge a certain dependency, execute the command below:

$ sudo yarn remove [package_name]

screenshot of Install Yarn on an Ubuntu

Installing All Dependencies

If you want to install the project dependencies specified in a package.json you can execute one of the commands below:

$ sudo yarn

Or

$ sudo yarn install

screenshot of Install Yarn on an Ubuntu

Conclusion

That is It! You have installed Yarn on Ubuntu 22.04 VPS or Dedicated server and learned how to implement some of the most commonly used Yar commands. For in-depth details regarding Yarn usage, go to the official Yarn documentation website page.

How to Install PrestaShop on an Ubuntu 18.04 VPS or Dedicated Server

This guide will show webmasters how to install the free shopping cart PrestaShop
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Install PhpMyAdmin on a Ubuntu 18.04 VPS or Dedicated Server

This article will describe the process of installing phpMyAdmin on an Ubuntu 18.
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Backup Your MySQL Database on an Ubuntu 18.04 VPS or Dedicated Server

This article shows you how to back up a MySQL database on a Linux Ubuntu 18.04 s
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Setup Fail2ban on your Ubuntu 18.04 VPS Server or Dedicated Server

In this guide, we discuss the steps needed for setting up Fail2ban on your Linux
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
Click to go to the top of the page
Go To Top
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.