Skip to main content
How To

Updating Yarn on Ubuntu

Learn to update the Yarn version installed on Ubuntu in this tutorial.

Sagar Sharma

Want to update Yarn and have no idea how to do it?

Well, in this tutorial, I will walk you through multiple ways you can update Yarn which include:

  • Updating globally installed Yarn
  • Updating Yarn for a specific project

So let's start with the first one.

Update globally installed Yarn

There are multiple ways you can install Yarn such as you can use the curl command, npm package manager (recommended way to install Yarn) or you can use homebrew.

Before you jump to the shown steps, it is recommended to know the currently installed version of Yarn:

yarn --version
Check the installed version of Yarn

Update through the install script

So if you used the installation script (involves usage of curl command) and now want to update it, then you can use the following command:

curl -o- -L | bash -s -- --version [version]

For example, if you want to upgrade to the Yarn version 1.22.0, then you use the following command:

curl -o- -L | bash -s -- --version 1.22.0
Update Yarn using the install script

Update through the npm package manager

Using the npm package manager is the officially recommended method for installing Yarn.

So if you followed the official documentation, here's where you will find steps to upgrade Yarn.

First, list the available versions for Yarn in the npm package manager:

npm view yarn versions
List available yarn versions while updating it through npm

Once you know the available versions, you can use the following command to update the Yarn:

sudo npm install --global yarn@<version_no>

For example, if I want to update Yarn to the version 1.21.1, then I will be using the following:

sudo npm install --global [email protected]

Update Yarn using homebrew

If you installed Yarn using homebrew, it can simply be updated using the following command syntax:

brew upgrade yarn

Yep, that's all you have to do!

Updating yarn for a specific project

Earlier, we used to use the yarn self-update command to update yarn for a specific project but in 2019, the Yarn team replaced it with the yarn policies set-version command.

When you use this command, it will modify the Yarn configuration in such a way that anyone using Yarn across the project will always use the configured Yarn version.

For this, all you have to do is execute the following command:

yarn policies set-version
update yarn for specific project

That's it!

Wrapping Up

This was a quick tutorial explaining how you can update Yarn using multiple methods.

And I really hope updating Yarn won't be a complex task anymore.

Sagar Sharma