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
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 -
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
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
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.
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
To install a package, us the syntax:
$ yarn add package
For example, to install express run the command:
$ yarn add express
To upgrade package, run
$ yarn upgrade package
If you wish to upgrade all your packages, run:
$ yarn upgrade
To remove a package, use the syntax
$ yarn remove package
For example:
$ yarn remove express
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.
With Debian 11 just run:
apt-get install -y yarnpkg