How to Install Yarn on Ubuntu Linux

This article describes the steps to install and use Yarn on Ubuntu Linux.

Yarn is a fast, reliable, and secure JavaScript dependency manager that can automate installing, updating, configuring, and managing npm packages.

If you’re a JavaScript programmer looking for an easier way to manage dependencies, Yarn is a great tool. Yarn is a fast, reliable, and secure JavaScript dependency manager that can automate installing, updating, configuring, and managing npm packages.

It caches every package it downloads, so it never needs to again. By installing Yarn on Ubuntu Linux, you can manage npm packages easily and guarantee that an install that worked on one system will work the same way on any other system.

For more about Yarn, please visit its homepage.

How to install and use Yarn on Ubuntu Linux

As described above, Yarn is a fast, reliable, and secure JavaScript dependency manager that automates installing, updating, configuring, and managing npm packages.

Below is how to install it on Ubuntu Linux.

Add Yarn APT Repository

Before installing Yarn, you should first install its package repository.

You’ll first need to add the repository’s GPG key to authenticate packages being installed from there. Run the commands below to add the Yarn repository’s GPG key to Ubuntu.

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

Next, run the commands below to add the repository

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

That’s all you need to install Yarn.

After that, run the commands below to install Yarn

sudo apt update
sudo apt install yarn

If you already have Node.js installed, simply run the commands below to install Yarn, but skip Node.js packages and dependencies.

sudo apt install --no-install-recommends yarn

Verify Yarn is Installed

To verify if Yarn is installed, run the commands below to print out the version number installed on your system.

yarn --version

The output should be something similar to the line below:

1.10.1

Now that you have Yarn installed on your Ubuntu system,  here are some of the most common commands you’ll need.

To create a new Yarn project, use the yarn init command as shown below:

yarn init myproject

The init script will ask you several questions. You can either answer or press to use the default values.

yarn init v1.10.1
question name (richard): 
question version (1.0.0): 
question description: 
question entry point (index.js): 
question repository url: 
question author: 
question license (MIT): 
question private: 
success Saved package.json
Done in 13.40s.

After that, the script will create a basic package.json file containing the information you provided above.

Upgrading dependencies

If you want to upgrade dependencies, simply run the commands below for each package and version you want to upgrade or update.

yarn upgrade
yarn upgrade [package_name]
yarn upgrade [package_name]@[version_or_tag]

If you do not provide a package name, Yarn will update all the project dependencies.

For more about using Yarn, check this page.

Conclusion:

This post showed you how to install Yarn on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report.

Frequently Asked Questions

What is Yarn and why should I use it?

Yarn is a fast, reliable, and secure JavaScript dependency manager that automates the installation, updating, configuration, and management of npm packages. It helps JavaScript programmers manage dependencies more efficiently and ensures consistent installs across different systems.

How do I add the Yarn APT repository on Ubuntu?

To add the Yarn APT repository on Ubuntu, you need to first install the repository's GPG key using the command 'curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -'. Then, add the repository by running 'echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list'.

What commands do I need to install Yarn on Ubuntu?

To install Yarn on Ubuntu, first run 'sudo apt update' and 'sudo apt install yarn'. If you already have Node.js installed, you can skip Node.js packages by using 'sudo apt install –no-install-recommends yarn'.

How can I verify that Yarn is installed correctly?

You can verify that Yarn is installed correctly by running the command 'yarn –version' in your terminal. If installed successfully, it will display the version number of Yarn, such as '1.10.1'.

What is the command to create a new Yarn project?

To create a new Yarn project, use the command 'yarn init myproject'. This will prompt you with several questions to set up your project's package.json file, which contains important information about your project.

Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *