Today we are going to learn that how to install Yarn on Ubuntu 20.04. It is the most reliable and the fast packages managements system with high security for the Node.js applications. It provides the facility of caching the downloaded packages on your system and then from the cache memory, reuse them when needed. So, you can save the time if you want to download the any package again or you need to download it many times. So, in this tutorial we’ll look over the 3 ways to install the Yarn on our Ubuntu 20.04 system. Simply follow the below steps for an easy installation.
- Adding Yarn Repository
- Installing Yarn with NPM
- Script installation of Yarn
We’ll see all these methods you can choose your desired one for installation purposes.
Step 1: Update Your System
First of all update your system to the latest one before going to install any package on your system. Type the below command in your terminal.
sudo apt udpate
Step 2: Install Yarn with Repository on Ubuntu 20.04
To install the Yarn with the repository on your system you have to add the repository first provided by the Yarn for Linux systems. Run the following command to import the GPG key for verification of Yarn package.
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Then type the given command to enable the Yarn repository.
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Now, update the system and install yarn with the given command. And press Y when prompted.
sudo apt update
sudo apt install yarn
Output:
You’ll see the similar output.
sabi@Ubuntu:~$ sudo apt install yarn
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
acl apg colord-data gnome-control-center-faces
gnome-online-accounts hplip-data libcolord-gtk1 libcolorhug2
libgsound0 libgssdp-1.2-0 libgupnp-1.2-0 libgupnp-av-1.0-2
libgupnp-dlna-2.0-3 libieee1284-3 libimagequant0 libmediaart-2.0-0
librygel-core-2.6-2 librygel-db-2.6-2 librygel-renderer-2.6-2
librygel-server-2.6-2 libsane-common libsnmp-base libwebpmux3
mobile-broadband-provider-info network-manager-gnome
printer-driver-postscript-hp python3-macaroonbakery python3-nacl
python3-olefile python3-pexpect python3-pil python3-protobuf
python3-ptyprocess python3-pymacaroons python3-renderpm
python3-reportlab python3-reportlab-accel python3-rfc3339
python3-tz rygel
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libc-ares2 libnode64 nodejs nodejs-doc
Suggested packages:
npm
The following NEW packages will be installed:
libc-ares2 libnode64 nodejs nodejs-doc yarn
0 upgraded, 5 newly installed, 0 to remove and 1 not upgraded.
Need to get 7,698 kB of archives.
After this operation, 36.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Verify the installed version by hitting the following command.
sabi@Ubuntu:~$ yarn --version
1.22.4
Step 3: Installing Yarn with NPM on Ubuntu 20.04
Fire the following command to install the Yarn on Ubuntu 20.04 with NPM.
sudo apt install npm
npm install -g yarn
-g: it will install the yarn globally on our system.
Step 4: Script installation of Yarn on Ubuntu 20.04
Install Yarn with script by hitting the below commands.
sudo apt install curl -y
curl -o- -L https://yarnpkg.com/install.sh | bash
Finally source the file.
source ~/.bashrc
That’s all!