Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. How to Install Yarn on Ubuntu

How to Install Yarn on Ubuntu

  • By Gcore
  • August 22, 2023
  • 2 min read
How to Install Yarn on Ubuntu

Understanding how to install Yarn on their systems is essential for developers aiming to streamline their project workflows in the Node.JS platform. Yarn offers a powerful alternative to default package managers (npm or Node Package Manager), ensuring speed, reliability, and consistency. It allows you to install, uninstall, and update packages. Suppose you’re running Ubuntu and want to leverage the benefits of Yarn. In that case, this guide will provide a walkthrough to help you seamlessly install Yarn and integrate it into your development routine.

What is Yarn?

Yarn is a package manager for JavaScript, introduced to address some of the challenges associated with npm (Node Package Manager), which was the default package manager for Node.js. Yarn was developed by Meta in collaboration with Exponent, Google, and Tilde.

Here are some key features and benefits of Yarn:

  1. Deterministic Dependency Resolution. Yarn uses a yarn.lock file to lock down the versions of package dependencies, ensuring that every install results in the exact same file structure in node_modules across all systems.
  2. Speed. Yarn caches every package it downloads, so it doesn’t need to repeatedly download them. This, in combination with parallelized operations, makes Yarn faster in many scenarios compared to npm.
  3. Security. Yarn uses checksums to verify the integrity of every package before its code is executed, ensuring that the package content is consistent and hasn’t been tampered with.
  4. Workspaces. It offers a feature called workspaces, which allows users to manage multiple projects with shared dependencies more effectively, making it a popular choice for monorepos.
  5. Compatibility with npm.  It is compatible with the npm registry, meaning that it can install any package that is available on npm.

Installing Yarn on Ubuntu

Here’s a step-by-step guide to installing Yarn on Ubuntu:

#1 Update package lists and install prerequisites

Before installing any new package on Ubuntu, it’s a good habit to update the package lists for the latest version of the repository.

sudo apt update

#2 Install the required dependencies

This step ensures that curl, a tool to fetch content from servers, and gnupg, a tool for secure communications, are installed.

sudo apt install curl gnupg -y

#3 Add Yarn APT repository to your system

This allows you to install Yarn and receive updates from Yarn’s own repository.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

#4 Update package lists again

Since you’ve added a new repository in the previous step, you’ll need to update the package lists once more.

sudo apt update

#5 Install Yarn

Now, you can install Yarn, using this command:

sudo apt install yarn

#6 Verify Installation

After the installation, it’s good to check the installed version of Yarn to ensure it was installed correctly.

yarn --version

And that’s it! Yarn is now successfully installed on your Ubuntu system, and you’re ready to use it to manage your JavaScript project dependencies.

Conclusion

Want to run Ubuntu in a virtual environment? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Ubuntu:

Choose an instance

Related articles

What's the difference between multi-cloud and hybrid cloud?

Multi-cloud and hybrid cloud represent two distinct approaches to distributed computing architecture that build upon the foundation of cloud computing to help organizations improve their IT infrastructure.Multi-cloud environments involve us

What is multi-cloud? Strategy, benefits, and best practices

Multi-cloud is a cloud usage model where an organization utilizes public cloud services from two or more cloud service providers, often combining public, private, and hybrid clouds, as well as different service models, such as Infrastructur

What is cloud migration? Benefits, strategy, and best practices

Cloud migration is the process of transferring digital assets, such as data, applications, and IT resources, from on-premises data centers to cloud platforms, including public, private, hybrid, or multi-cloud environments. Organizations can

What is a private cloud? Benefits, use cases, and implementation

A private cloud is a cloud computing environment dedicated exclusively to a single organization, providing a single-tenant infrastructure that improves security, control, and customization compared to public clouds.Private cloud environment

What is a cloud GPU? Definition, types, and benefits

A cloud GPU is a remotely rented graphics processing unit hosted in a cloud provider's data center, accessible over the internet via APIs or virtual machines. These virtualized resources allow users to access powerful computing capabilities

What is cloud networking: benefits, components, and implementation strategies

Cloud networking is the use and management of network resources, including hardware and software, hosted on public or private cloud infrastructures rather than on-premises equipment. Over 90% of enterprises are expected to adopt cloud netwo

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.