How to Install Yarn on Ubuntu 20.04 Focal Fossa Linux

In this article you will learn how to install Yarn, the JavaScript package manager on Ubuntu 20.04 Focal Fossa Linux.

In this tutorial you will learn:

  • How to add Yarn repository
  • How to install Yarn

Yarn on Ubuntu 20.04 Focal Fossa Linux

Yarn on Ubuntu 20.04 Focal Fossa Linux

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software Yarn
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install Yarn on Ubuntu 20.04 step by step instructions

Yarn Installation using the Ubuntu repository

  1. Install the yarnpkg package:
    $ sudo apt install yarnpkg
    
  2. Check yarn version:
    $ yarnpkg --version
    1.22.4
    

Yarn Installation using the official Yarn repository

  1. Add Yarn repository by executing the below commands:
    $ sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    $ sudo sh -c "echo 'deb https://dl.yarnpkg.com/debian/ stable main' >> /etc/apt/sources.list"
    $ sudo apt update
    
  2. Install Yarn on your system. In case you have already installed Node.js on your Ubuntu 20.04 system you can avoid its installation by:
    $ sudo apt --no-install-recommends install yarn
    

    Otherwise simply executing the below command:

    $ sudo apt install yarn
    

    which will install yarn as well as Node.js from the standard Ubuntu repository.

  3. Check the yarn version:
    $ yarn --version