How to Install Yarn on Ubuntu Linux?
Yarn on Ubuntu Linux is a popular package manager that downloads, updates, and tracks the code libraries your JavaScript projects need to run. It acts as a faster alternative to npm (Node Package Manager), helping you keep your project files organized and working the exact same way on every computer.
Installing Yarn on Ubuntu versions like 22.04 or 24.04 takes just a few minutes using your terminal. Once set up, it saves copies of your downloaded packages in a local cache so you can install them offline or much faster next time.
Add the Yarn repository and its GPG key, then install Yarn using apt. Run `sudo apt update`, `sudo apt install curl`, `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`, and finally `sudo apt install yarn`.
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
Adding the Yarn APT repository to your Ubuntu system lets your package manager locate and install Yarn safely. You need to set up this software source and its security key before you can download the application using your terminal.
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
Verifying your Yarn installation confirms that the tool is ready to use on your Ubuntu system. You can check the installed version by running a quick command in your terminal and looking for the version number in the output.
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.
You can create a new Yarn project by running the `yarn init` command in your terminal. This command starts the Yarn package manager's initialization process, guiding you through setting up the `package.json` file, which holds information about your project and its dependencies.
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
Upgrading dependencies keeps your project packages current with the latest bug fixes and features. You can update every package in your project at once or target a specific package by name and version using the terminal.
yarn upgrade yarn upgrade [package_name] yarn upgrade [package_name]@[version_or_tag]
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.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!