Yarn is a reliable, well-maintained, and proven utility that will work wonders in managing software on your system.
This article will show you how to get yarn working on your Ubuntu 20.04 system. Read carefully and follow the instructions below.
Step 1: Install Yarn’s Package Repository
Before installing Yarn, you must add the Yarn ATP repository on your system.
First, make sure the packages are from the official sources by adding the repository’s GPG key. Enter the following commands to add the Yarn repository’s GPG key to your system.
To add the yarn repository with the GPG key, start a terminal and enter the following commands:
Then enter the following to add the repository:
sudo tea /Etc/suitable/Sources.list.d/Yarn list
The system is now ready to add yarn to its active programs.
Step 2: Install Yarn on your Ubuntu 20.04 system
After completing the above step, you can now proceed to install Yarn. Check if you have Node.js on your system. If Node.js is pre-installed, you can custom install yarn by running the following command:
Otherwise, if Node.js is not pre-installed, you will need to download the Node.js dependencies with Yarn.
Here’s how you can install Yarn on your Ubuntu 20.04 computer.
Step 3: check the installation
With Yarn now installed on your system, all you have to do is check that the installation was up to date. Enter the following commands to start the installation.
This should print out the version of yarn your system has, display the number, and thereby verify the installation.
We’re now going to look at some of the basics to get you started with yarn.
Step 4: getting started with yarn
After you finish the installation, it is time to familiarize yourself with some of the basic commands used in Yarn.
Some of the commands you will frequently need when using yarn include the following.
Start a new project
Enter the following command to create a directory for your new project:
Then build your project with the following line:
You will be asked for the specifications of your project, which you can answer yourself, or simply use the standard values.
The script creates your project’s package.json file to get you started.
Add and update dependencies
You can attach an npm package to a file you’ve created using the following command:
To add an npm package to the project dependencies, use the yarn add command followed by the package name:
This should update your package.json file. Note that if you just add the package name, Yarn will install the latest version. Enter the code below to upgrade to a version of your choice.
Remove a dependency
You can also remove a dependency. Enter the following command:
Notice that your project’s package.json and Garn.lock files are also updated.
Automate the installation of all dependencies
You can also automate the installation of all project dependencies contained in your package.json project file. To do this, enter the following command:
This article describes how to install Yarn on the latest Ubuntu version from April 20th. The article also covers creating new project files and updating them and their dependencies.
With Yarn installed on your system, you can use the Yarn APT repository to manage npm packages very efficiently. Yarn records which version update worked on which systems and works out the optimal solution for upgrading your dependencies. The official repository for Yarn is regularly updated and maintained to give you the latest versions of the software you download.
To learn more about Yarn, visit the official website.