• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Yarn on Ubuntu 20.04 LTS

Written by Admin, Updated On May 10, 2020
nodejs, npm, ubuntu, yarn
How to Install Yarn on Ubuntu 20.04

Yarn is a latest package manager for Node.js. It’s much faster than npm and installs packages simultaneously. Which allows to install, update, configure, and remove npm packages with improvements over npm. This guide covers how to install Yarn on Ubuntu 20.04 Focal Fossa system and basic use of yarn to create a new project.

Prerequisite#

  • Make sure that you are logged in as root or user with sudo privileges to install Yarn on Ubuntu 20.04.
  • Before you go ahead, make sure you have installed Node.js on your Ubuntu system.

Step 1 – Add Repository#

Before the installation of yarn, you have to add the GPG key to verify the yarn packages. To import GPG type the following command on the terminal:

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

Step 2 – Enable Yarn Repository#

To install yarn on your system, you need enable the yarn repository. To do so, type the following command:

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

Step 3 – Install Yarn#

Once the repository is enabled, update the apt cache and install Yarn, type:

sudo apt update && sudo apt install yarn

Step 3 – Check Yarn Version#

To verify the installation check the version by typing:

yarn --version
1.22.4

Using Yarn#

At this stage, Yarn is installed on your Debian system. Now we will some basic usage of Yarn commands:

Create a new project#

You need to use yarn init command followed by the project name to create a new Yarn project. For example, to create a project with name demo type:

yarn init demo

You will be prompted for few questions. Give answers for it or you can skip by pressing Enter key.

It will create a package.json file which contains all the information which you provided.

For existing project you also can initiate yarn, navigate to directory and run:

yarn init

Adding dependency#

Add a package to your project, use the yarn add command followed by the package name:

yarn add PACKAGE_NAME

The above command will install latest version of the package and update the project’s package.json and yarn.lock files. For a specific version of package specify version as following:

yarn add PACKAGE_NAME@VERSION

Upgrading dependency#

You can update the packages by simple use of following command:

yarn upgrade

It will update all the project dependencies to their latest version. You can specify the package name and version for specific update.

Removing dependency#

To remove a package from the project’s dependencies, use the yarn remove command followed by the package name:

yarn remove PACKAGE_NAME

Installing all project dependencies#

To install all the dependencies of an existing project that are specified in the package.json file run:

yarn install

Conclusion#

Congratulations! The yarn has been successfully installed on your system Ubuntu 20.04 LTS. This guide also covers use of common commands of yarn. You can learn more about Yarn at documentation page.

If you have any questions or suggestion, leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Set Up Apache Virtual Hosts on CentOS 8
Next Article   How to Set Up Nginx Server Blocks on CentOS 8

Related Posts

  • How to Install Php 8 on Ubuntu 20.04

    How to Install PHP 8 on Ubuntu 20.04

    December 28, 2020
  • How to Install GIMP on Ubuntu 20.04

    How to Install GIMP 2.10 on Ubuntu 20.04

    December 22, 2020
  • How to Install Python 3.9 on Ubuntu 20.04

    How to Install Python 3.9 on Ubuntu 20.04

    December 21, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP 2.10 on CentOS 8
    How to Install GIMP 2.10 on CentOS 8 December 30, 2020
  • How to Install AnyDesk on Debian 10
    How to Install AnyDesk on Debian 10 Buster January 23, 2021
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook