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?
Here are some key features and benefits of Yarn:
- 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.
- 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.
- 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.
- 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.
- 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.
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:
- Gcore Basic VM offers shared virtual machines from €3.2 per month
- Virtual Instances are virtual machines with a variety of configurations and an application marketplace
- Virtual Dedicated Servers provide outstanding speed of 200+ Mbps in 20+ global locations