How should yarn
be upgraded to the latest version?

- 24,334
- 12
- 145
- 143

- 4,769
- 5
- 29
- 34
24 Answers
For macOS users, if you installed yarn
via brew
, you can upgrade it using the below command:
brew upgrade yarn
On Linux, just run the below command at the terminal:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
On Windows, upgrade with Chocolatey
choco upgrade yarn
Credits: Added answers with the help of the below answers

- 4,265
- 2
- 34
- 58

- 6,011
- 5
- 42
- 58
-
15tagged for Ubuntu, not MacOs. – Luciano Bargmann Aug 07 '19 at 17:31
-
27Google does not check the tag when routing users to this question. – shredding Oct 31 '19 at 12:07
-
3You can do it faster with: `(npm uninstall -g yarn && brew install yarn) || brew upgrade yarn` – user9869932 Feb 12 '20 at 19:32
-
2Note that installing `yarn` via `brew` also installs `node`. This may be undesired if, for instance, you are using `nvm` or `n`. – Jeff Fairley Jun 04 '20 at 22:59
-
@LucianoBargmann I have brew on my Linux install so it's not a bad answer for these few people who upgrade in this very way. – Alexis Wilke Dec 09 '20 at 16:50
-
Using `brew` was the only thing that worked for me on OS X – Anthony Nov 03 '21 at 16:04
npm install --global yarn
npm upgrade --global yarn
This should work.

- 9,564
- 146
- 81
- 122

- 1,891
- 1
- 9
- 11
-
11> Note: Installation of Yarn via npm is generally not recommended. When installing Yarn with Node-based package managers, the package is not signed, and the only integrity check performed is a basic SHA1 hash, which is a security risk when installing system-wide apps. https://yarnpkg.com/lang/en/docs/install/#alternatives-stable – mnishiguchi Jun 27 '18 at 16:15
-
1I am pretty sure you can no longer install/upgrade yarn though `npm`, rather you need to do it throw `brew` on OSX at least. – Dragos Rizescu Sep 16 '18 at 12:36
-
3Since this question was specifically about Ubuntu 16.04, comments about OSX and `brew` are not really relevant. I just did upgrade yarn through `npm upgrade --global yarn` on Ubuntu 16.04 where I had installed yarn through npm earlier. So pretty sure, it is still possible, even though that's not the recommended way. My original reason for installing yarn through npm was that I'm using `nvm` to keep multiple versions of `node`. Installing yarn through `apt` would have installed a specific version of node globally. But I read this can be avoided through the parameter `--no-install-recommends`. – trollkotze Nov 11 '18 at 11:45
-
4@mnishiguchi the page you linked does not contain the quoted text. in fact, it contains the opposite statement: "It is recommended to install Yarn through the npm package manager" – naXa stands with Ukraine Nov 29 '21 at 12:12
-
-
I just checked Yarn website and I found this: It is recommended to install Yarn through the npm package manager, which comes bundled with Node.js when you install it on your system. Once you have npm installed you can run the following both to install and upgrade Yarn: `npm install --global yarn` ref: https://classic.yarnpkg.com/en/docs/install/#alternatives-stable – Ezequiel Guitler Jul 07 '23 at 12:06
Not remembering how i've installed yarn the command that worked for me was:
yarn policies set-version
This command updates the current yarn version to the latest stable.
From the documentation:
Note that this command also is the preferred way to upgrade Yarn - it will work no matter how you originally installed it, which might sometimes prove difficult to figure out otherwise.

- 2,091
- 4
- 25
- 40
-
3Its also worth noting that this command creates `.yarn/` and `.yarnrc` – random-forest-cat May 21 '19 at 18:50
-
8
-
This command didn't work for me, it return the error: ` error Couldn't find a package.json file in "/home/.."` – Eyong Kevin Enowanyo Jan 19 '20 at 04:35
-
1I guess it didn't work because I installed my `yarn` with `apt-get`. I think it is possible to know how you installed your package. For me, I do `npm list -g >filename.txt`, then I search the file for any package needed. For apt-get, I do `apt list --installed`, then I check the output for the package needed. – Eyong Kevin Enowanyo Jan 19 '20 at 04:50
On Linux, just run below command at terminal:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
After do this, close the current terminal and open it again. And then, run below command to check yarn current version:
$ yarn --version

- 1,787
- 17
- 14
-
3
-
1Works on git bash but shows the same older version when you run `yarn --version` on command prompt. – Niraj Niroula Oct 14 '19 at 10:54
-
@NirajNiroula You will need to re-open the terminal in order to see any changes. – Marios Ath Feb 05 '21 at 17:04
-
I tried this and it didn't work regardless of whether I opened a new terminal. For me `npm install --global yarn` worked in Ubuntu – Wellspring Mar 30 '21 at 22:08
yarn policies set-version
will download the latest stable release
Referenced yarn docs https://yarnpkg.com/lang/en/docs/cli/policies/#toc-policies-set-version

- 487
- 4
- 3
-
Note that you can specify the version with this command too. e.g. `yarn policies set-version 1.21.0` – Edmund Lee Jan 09 '20 at 21:56
-
This command didn't work for me, it return the error `error Couldn't find a package.json file in "/home/.."` – Eyong Kevin Enowanyo Jan 19 '20 at 04:34
-
This is typically used for setting a policy for a shared team project, not for updating/upgrading a global installation – marchWest Jan 15 '22 at 00:45
Works on all OS's
yarn set version latest
yarn set version from sources
Worked without the second line for me, but it is in the documentation for some reason.

- 436
- 5
- 10
-
-
the 2nd line produces error `error An unexpected error occurred: "Release not found: from".` – naXa stands with Ukraine Jan 12 '23 at 17:32
-
Only `yarn set version latest` should be used, the second command use unstable version from git https://yarnpkg.com/cli/set/version/from/sources – Chris' Mar 17 '23 at 09:39
npm install -g yarn
- solved the issue when nothing happened running npm update --global yarn
.
Alternative method to update yarn: curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
.
Mac users with homebrew can run brew upgrade yarn
.

- 1,937
- 1
- 19
- 23
-
If `npm update --global yarn` didn't work but `npm install -g yarn` did it's possible it wasn't installed by npm in the first place. – Jesse Proulx Feb 27 '20 at 02:11
-
-
I had to remove Yarn from *Program Files (x86)* first before installing with `npm`. – Qwerty Jan 04 '22 at 18:37
I had an outdated symlink that was preventing me from accessing the proper bin. I had also recently gone through a node upgrade which means a lot of my newer bins were available in a different folder with what i think was a lower priority
Here is what worked for me:
yarn -v
> 1.15.2
which yarn
> /Users/lfender/.yarn/bin/yarn
rm -rf /Users/lfender/.yarn/bin/yarn
npm uninstall --global yarn; npm install --global yarn
> + yarn@1.16.0
> added 1 package in 0.179s
which yarn
> /Users/lfender/.nvm/versions/node/v12.2.0/bin/yarn
yarn -v
> 1.16.0
If you are not using NVM, the location of your bin installs are likely to be unique to your system
From there, I've switched to doing yarn policies set-version
as outlined here https://stackoverflow.com/a/55278430/1426788 to define my yarn version at the repo level

- 33,652
- 11
- 120
- 99
According to https://yarnpkg.com/getting-started/install#updating-to-the-latest-versions
yarn set version <version>
For example to upgrade yarn v1.22.4 to v1.22.10:
yarn set version 1.22.10

- 467
- 5
- 9
I updated yarn on my Ubuntu by running the following command from my terminal
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
source:https://yarnpkg.com/lang/en/docs/cli/self-update

- 73
- 1
- 3

- 1,991
- 19
- 16
- Add Yarn Package Directory:
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
- Install Yarn:
sudo apt-get update && sudo apt-get install yarn
Please note that the last command will upgrade yarn to latest version if package already installed.
For more info you can check the docs: yarn installation

- 2,164
- 2
- 29
- 39

- 73
- 1
- 3
-
1
-
This solution works if you had installed `yarn` with `apt-get`. It worked for me on `Ubuntu 16.04` – Eyong Kevin Enowanyo Jan 19 '20 at 04:54
If you already have yarn 1.x
and you want to upgrade to yarn 2. You need to do something a bit different:
yarn set version berry
Where berry
is the code name for yarn version 2. See this migration guide here for more info.

- 66,950
- 18
- 261
- 230
I tried at first
yarn policies set-version
Then it directed me to run
yarn set version stable
You should implement them in order, the first command will download your current yarn version and update .yarnrc after that running the second command will upgrade yarn successfully to the latest stable version

- 81
- 2
I tried all of the above solutions in Jenkins pipeline which needs the latest yarn. Finally, this worked for me.
- Run yarn policies set-version in the git repo
- This will generate .yarn/releases/yarn-X.X.X.js file and .yarnrc file. Push both of these files in the Git repo.
- Now build and all the yarn commands will use the yarn-X.X.X version.
Note: This is helpful when you don't have root access to npm install -g yarn.

- 1,081
- 3
- 24
- 45
npm i -g yarn
This should update your yarn version. Check version with yarn -v
or yarn --version
.

- 5,644
- 7
- 24
- 54

- 31
- 2
yarn policies set-version --rc
As per the yarn documentation to update yarn to latest version we should run the above command. Check version with yarn -v
or yarn --version
.
Ref : https://classic.yarnpkg.com/en/docs/cli/policies/#toc-policies-set-version

- 327
- 3
- 8
yarn policies set-version
Use the above command in powershell to upgrade your current yarn version to Latest.It will download the latest yarn release

- 99
- 1
- 9
If You want to upgrade your yarn version from 1.22.5 to 1.22.10
yarn policies set-version

- 9
- 1
This work for me to change yarn version 0.32
git to 1.22.5
https://www.codegrepper.com/code-examples/shell/yarn+0.32+git+ubuntu

- 21
- 1
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 17 '21 at 18:31
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/29853964) – Adrian Mole Sep 17 '21 at 19:30
-
Although the format needs improvements, this answer is the only one worked for me. – user810992 Mar 08 '23 at 20:30
To upgrade to latest version of yarn, run the below command on your terminal.
"yarn set version latest -g"

- 1
- 1
Assuming you're on yarn version 2 and above. Then you can run yarn set version stable
to upgrade to the latest stable version.
You can read more at the docs

- 3,209
- 2
- 21
- 29
Since you already have yarn installed and only want to upgrade/update. you can simply use
yarn self-update
Find ref here https://yarnpkg.com/en/docs/cli/self-update

- 1
- 1
-
1This is not a solution. If you checked the page, it says "Note: self-update is not available. See policies for enforcing versions within a project" – Emobe May 18 '19 at 13:30
-
-