How to Install Yarn on Debian 10

Yarn is a JavaScript package manager developed by Facebook that provides a list of benefits over its counterpart NPM. Some of these include: Faster rate of package downloads, ability to download offline packages and auto-generation of lock files. In this brief tutorial, we will give you an overview of how to install and use Yarn on Debian 10.

Let’s begin!

Step 1) Create a Yarn repository

Since Yarn is not yet available on Debian 10’s official repository, we are going to locally add the Yarn’s repo manually on our system. But first, let’s update and upgrade the system packages:

$ sudo apt update -y
$ sudo apt upgrade -y

Debian10-apt-update-output

Next, we are going to install the GPG signing key as shown:

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

add-yarn-debian10-repository-key

To create the Yarn repository, run the command:

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

add-yarn-debian10-repo

Step 2) Install Yarn

With the repository created, re-synchronize the system packages by updating the system:

$ sudo apt update -y

Finally, to install Yarn run the command:

$ sudo apt install yarn

apt-install-yarn-debian10

Once the installation is complete, you can check the version of Yarn installed by running the command:

linuxtechi@debian10:~$ yarn -v
1.21.1
linuxtechi@debian10:~$
OR
linuxtechi@debian10:~$ yarn -v
1.21.1
linuxtechi@debian10:~$

Perfect ! We have successfully installed Yarn on Debian 10. Let’s now see a few use cases of how yarn can be used.

How to use Yarn

Yarn writes dependencies on the package.json file that is located on the root folder of your project and stores these dependencies in the node_modules directory.

To initialize a project simply run the command:

$ yarn init

A series of questions will be asked to which you will be required to answer accordingly. You can opt to leave some of them blank if you so wish.

yarn-initialize-debian10

The initialization of a new project creates a package.json file as mentioned earlier that contains the details you have just provided. To view the file, run

$ cat package.json

package-jason-yarn-debian10

To install a package, us the syntax:

$ yarn add package

For example, to install express run the command:

$ yarn add express

yarn-add-debian10

To upgrade package, run

$ yarn upgrade package

If you wish to upgrade all your packages, run:

$ yarn upgrade

yarn-upgrade-debian10

To remove a package, use the syntax

$ yarn remove package

For example:

$ yarn remove express

yarn-remove-package-debian10

And that’s just about it as far as the installation of yarn is concerned. Yarn is a package Manager that is slowly but surely gaining traction and looking to replace Node’s NPM package manager. It’s fast and allows developers to share code in a seamless and secure way.

Share Now!

1 thought on “How to Install Yarn on Debian 10”

Leave a Comment