Yarn: How to upgrade yarn version using terminal?
Asked Answered
A

24

253

How should yarn be upgraded to the latest version?

Achorn answered 6/4, 2018 at 9:3 Comment(0)
E
260

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

Echelon answered 22/5, 2018 at 5:43 Comment(6)
tagged for Ubuntu, not MacOs.Nicholnichola
Google does not check the tag when routing users to this question.Artois
You can do it faster with: (npm uninstall -g yarn && brew install yarn) || brew upgrade yarnDaren
Note that installing yarn via brew also installs node. This may be undesired if, for instance, you are using nvm or n.Khoisan
@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.Isabellaisabelle
Using brew was the only thing that worked for me on OS XDorrie
T
188
npm install --global yarn
npm upgrade --global yarn 

This should work.

Tarlatan answered 6/4, 2018 at 9:6 Comment(6)
> 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. yarnpkg.com/lang/en/docs/install/#alternatives-stableOhl
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.Sinuosity
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.Dagley
@Ohl 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"Rigorism
Maybe things are different now in 2021 ¯_(ツ)_/¯Ohl
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: classic.yarnpkg.com/en/docs/install/#alternatives-stableAfresh
E
135

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

Evangelina answered 21/3, 2019 at 10:32 Comment(4)
Its also worth noting that this command creates .yarn/ and .yarnrcPickle
It did not update Yarn globally, only in the current project.Illfavored
This command didn't work for me, it return the error: ` error Couldn't find a package.json file in "/home/.."`Rhianna
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.Rhianna
A
70

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
Aviv answered 11/1, 2019 at 13:34 Comment(4)
Works on OSX as wellDumah
Works on git bash but shows the same older version when you run yarn --version on command prompt.Nosing
@NirajNiroula You will need to re-open the terminal in order to see any changes.Grease
I tried this and it didn't work regardless of whether I opened a new terminal. For me npm install --global yarn worked in UbuntuSomaliland
L
48

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

Leastways answered 9/12, 2019 at 17:25 Comment(3)
Note that you can specify the version with this command too. e.g. yarn policies set-version 1.21.0Kovach
This command didn't work for me, it return the error error Couldn't find a package.json file in "/home/.."Rhianna
This is typically used for setting a policy for a shared team project, not for updating/upgrading a global installationPasqualepasqueflower
T
39

For Windows users

I usually upgrade Yarn with Chocolatey.

choco upgrade yarn
Trapezium answered 10/12, 2018 at 17:9 Comment(0)
S
34

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

Spicy answered 3/10, 2021 at 8:14 Comment(3)
Be careful. It works but broke global add for me.Halverson
the 2nd line produces error error An unexpected error occurred: "Release not found: from".Rigorism
Only yarn set version latest should be used, the second command use unstable version from git yarnpkg.com/cli/set/version/from/sourcesBevis
G
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.

Geoffrey answered 26/12, 2018 at 15:27 Comment(3)
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.Chemotropism
thanks, it worked for me. upgraded to yarn 1.22.4 from yarn 1.19.1Mauricio
I had to remove Yarn from Program Files (x86) first before installing with npm.Tournedos
P
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

> + [email protected]
> 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://mcmap.net/q/109644/-yarn-how-to-upgrade-yarn-version-using-terminal to define my yarn version at the repo level

Pickle answered 21/5, 2019 at 18:48 Comment(0)
M
19

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
Meeker answered 23/9, 2021 at 16:37 Comment(1)
Or latest: yarn set version stableZymometer
W
10

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

Weakly answered 1/12, 2019 at 12:42 Comment(1)
Thank you Merabi. The source is really useful.Weakly
S
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

Samaria answered 13/8, 2018 at 12:19 Comment(2)
This solution worked for me on Windows 10 ubuntu WSL terminal with zsh.Vaientina
This solution works if you had installed yarn with apt-get. It worked for me on Ubuntu 16.04Rhianna
K
6

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.

Khz answered 29/9, 2020 at 9:12 Comment(0)
S
5

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

Supinate answered 31/10, 2022 at 9:39 Comment(0)
S
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.

Solingen answered 3/7, 2020 at 14:33 Comment(0)
B
1
npm i -g yarn

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

Bushman answered 30/1, 2022 at 11:47 Comment(1)
yarn -v will be effective at new terminal tabCeramist
K
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

Kathikathiawar answered 8/9, 2022 at 0:16 Comment(0)
S
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

Smokeless answered 21/9, 2020 at 11:46 Comment(0)
W
0

yarn policies set-version

this upgraded my yarn version from 1.22.5 to 1.22.10

Willey answered 23/3, 2021 at 4:59 Comment(0)
A
0

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

yarn policies set-version

Abbotson answered 19/4, 2021 at 6:4 Comment(0)
A
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

Amphibian answered 17/9, 2021 at 16:45 Comment(3)
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.Aldershot
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 ReviewLamm
Although the format needs improvements, this answer is the only one worked for me.Arroba
B
0

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

"yarn set version latest -g"

Bureaucratic answered 7/9, 2022 at 9:59 Comment(0)
S
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

Septempartite answered 15/4, 2023 at 16:9 Comment(0)
A
-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

Azores answered 16/5, 2019 at 7:59 Comment(3)
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"Haploid
why would they even have the page? that's confusing.Nonbeliever
Why is this even a page. And it is a Google ranking page too. Ughh..Nordrheinwestfalen

© 2022 - 2024 — McMap. All rights reserved.