For building any web server or any other application that will require internet access to function mostly javascript is used as a scripting language along with Node.js runtime environment. Further to add any functionalities to such applications or web servers a package manager is required. There are two package managers named node package manager (npm) and yarn (yet another resource navigator) used for this purpose.
Yarn is usually preferred by most of users for several reasons, it is supported on different operating systems including the newly released Ubuntu 24.04. This guide is about the installation of the yarn javascript package manager on Ubuntu 24.04.
Outline:
Yarn is an open-source package manager specifically used for managing javascript project dependencies. Just like the Ubuntu package manager, it serves the purpose of streamlining the process of installing, updating, configuring, and removing package dependencies.
Yarn offers various features which include workspaces, offline caching, and parallel installs which result in improvements in speed, reliability, and security. These features make it preferable when compared with the node package manager, to Install yarn on Ubuntu 24.04 there are four ways:
Installing an application on Ubuntu 24.04 via the application repository is beneficial in two cases one if the application package is not present in apt or the version of the package in apt is old. For yarn, the second case is true so to install a relatively newer version use its official repository. Yarn comes with three types of versions which are:
To install any of the three using the add repository method you have to add the yarn repository for the respective yarn version. Here. for illustration, I have added the repository for the developmental version which is the nightly version. First, I have added the GPG key for yarn and the command for all of the versions will be the same:
Now fetch the yarn repository and save it in sources.list directory:
To apply the changes or to successfully add the yarn repository in Ubuntu 24.04 update the packages list and then use apt to install yarn:
Once the installation is complete you can verify it by checking its version. Further to install the stable version of yarn add the following repository:
Similarly, install the pre-release version of Yarn on Ubuntu 24.04 by executing:
Note: Yarn on Ubuntu 24.04 can be installed via the default package installer without adding the repository. However, the version in apt is quite old and you might get an error or encounter issues using it due to cmdtest utility.
Since Yarn is the package manager for javascript projects that use Node.js as their runtime environment it can be installed on Ubuntu 24.04 by using the node package manager. However, first, the npm should be installed using Ubuntu’s default package installer:
Now install Yarn via npm, here g flag is used to install a global version of Yarn which provides the privilege of accessing it from any directory of the system:
Correpack is a Node.js script that serves as a bridge between the Node.js projects and the package managers used during the server or app development. In other words, Corepack allows to use yarn package manager without installing it separately.
If the Node.js or npm is already installed on Ubuntu 24.04 then Corepack may also be pre-installed you can check by using the version command. To install Corepack use the node package manager:
After the installation enable this script:
Now prepare and activate the stable version of the Yarn package manager:
Now execute the yarn command and it asks to add the tar file for version 1.22.19 so prompt it:
Now as you can see an older version is installed so if you want to update it to the latest version then use the up command along with Corepack:
If you are looking for an easy way to install Yarn on Ubuntu 24.04 then try this method as this method bash script file for yarn is downloaded from its official website. The downloaded bash file is then executed using the bash command. So in other words the file Yarn package manager is installed directly from the internet:
On the completion of the command execution, there will be a completion message showing the version installed:
To make Yarn work properly you need to reboot the system. In the above image, I have installed the stable version of Yarn so to install the pre-release version execute:
On the other hand to install the development version execute:
Based on the usage and compatibility you might need to upgrade or downgrade the version of Yarn and for that you can use the set version command along with the version name:
Or you can use the version number that you want to use:
The process of removing Yarn on Ubuntu 24.04 varies since there are several different ways to install it. To remove Yarn from Ubuntu 24.04 if installed via Yarn repository then execute:
Next, remove the repository from the sources.list directory:
Also, remove the GPG key for yarn and for that first find its key number by listing all the keys:
Now use the last four key combinations along with the del command ti remove the Yarn GPG key from Ubuntu 24.04:
To uninstall Yarn if installed via the node version manager execute:
To remove the Yarn package manager through Corepack first disable it and then remove it using the node package manager:
sudo npm uninstall -g corepack
In case Yarn is installed through a bash file then first locate the directory in which it is installed and for that execute:
Now remove the directory which will result in Yarn uninstallation:
Yarn is a javascript project package manager used to add functionalities or features in the application or server under development. To install Yarn in Ubuntu 24.04, use the Yarn repository, node package manager, Corepack, or installation script from the official source. You can also select three versions for Yarn: stable, pre-released, and development version. Further, you can also switch between the Yarn version by using the set version command.
Welcome to the Ubuntu Weekly Newsletter, Issue 883 for the week of March 9 –…
In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…
In this article, we will see how to install clang tool on Ubuntu or Debian…
When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…
You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…
Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…