244

How should yarn be upgraded to the latest version?

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Janaka Pushpakumara
  • 4,769
  • 5
  • 29
  • 34

24 Answers24

247

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

Jimit Patel
  • 4,265
  • 2
  • 34
  • 58
sonlexqt
  • 6,011
  • 5
  • 42
  • 58
184
npm install --global yarn
npm upgrade --global yarn 

This should work.

Pang
  • 9,564
  • 146
  • 81
  • 122
Abdul Rahman
  • 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
  • 1
    I 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
  • 3
    Since 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
  • Maybe things are different now in 2021 ¯\_(ツ)_/¯ – mnishiguchi Nov 30 '21 at 13:07
  • 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
126

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.

Reference

Agu V
  • 2,091
  • 4
  • 25
  • 40
  • 3
    Its also worth noting that this command creates `.yarn/` and `.yarnrc` – random-forest-cat May 21 '19 at 18:50
  • 8
    It did not update Yarn globally, only in the current project. – Tonatio Nov 24 '19 at 20:31
  • 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
  • 1
    I 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
69

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
Janderson Silva
  • 1,787
  • 17
  • 14
47

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

39

For Windows users

I usually upgrade Yarn with Chocolatey.

choco upgrade yarn
Pang
  • 9,564
  • 146
  • 81
  • 122
SandroMarques
  • 6,070
  • 1
  • 41
  • 46
27

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.

Reference

Ahmed
  • 436
  • 5
  • 10
23

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.

More details here and here.

Yuriy Rypka
  • 1,937
  • 1
  • 19
  • 23
19

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

random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
15

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
Piyush Khera
  • 467
  • 5
  • 9
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

Roshimon
  • 1,991
  • 19
  • 16
7
  1. 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

  1. 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

Afaq Ahmed Khan
  • 2,164
  • 2
  • 29
  • 39
4

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.

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
2

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

A.A.
  • 81
  • 2
1

I tried all of the above solutions in Jenkins pipeline which needs the latest yarn. Finally, this worked for me.

  1. Run yarn policies set-version in the git repo
  2. This will generate .yarn/releases/yarn-X.X.X.js file and .yarnrc file. Push both of these files in the Git repo.
  3. 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.

Chandresh Mishra
  • 1,081
  • 3
  • 24
  • 45
1
npm i -g yarn

This should update your yarn version. Check version with yarn -v or yarn --version.

Mahdi Zarei
  • 5,644
  • 7
  • 24
  • 54
1
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

0

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

SachinT
  • 99
  • 1
  • 9
0

yarn policies set-version

this upgraded my yarn version from 1.22.5 to 1.22.10

0

If You want to upgrade your yarn version from 1.22.5 to 1.22.10

yarn policies set-version

0

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

  • 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
0

To upgrade to latest version of yarn, run the below command on your terminal.

"yarn set version latest -g"

0

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

Kristian Roebuck
  • 3,209
  • 2
  • 21
  • 29
-9

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

Stephen
  • 1
  • 1
  • 1
    This 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
  • why would they even have the page? that's confusing. – Julix Dec 13 '19 at 00:43
  • Why is this even a page. And it is a Google ranking page too. Ughh.. – GN. May 12 '20 at 21:39