Janaka Pushpakumara
Janaka Pushpakumara

Reputation: 5107

Yarn: How to upgrade yarn version using terminal?

How should yarn be upgraded to the latest version?

Upvotes: 270

Views: 390790

Answers (24)

Kristian Roebuck
Kristian Roebuck

Reputation: 3379

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

Upvotes: 1

A.A.
A.A.

Reputation: 251

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

Upvotes: 10

Aryashree Pritikrishna
Aryashree Pritikrishna

Reputation: 351

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

Upvotes: 1

Sunil Kumar N
Sunil Kumar N

Reputation: 21

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

"yarn set version latest -g"

Upvotes: 2

Sunil Panwar
Sunil Panwar

Reputation: 31

npm i -g yarn

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

Upvotes: 1

Ahmed
Ahmed

Reputation: 636

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

Upvotes: 47

Piyush Khera
Piyush Khera

Reputation: 527

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

Upvotes: 21

Ethan Cohen
Ethan Cohen

Reputation: 21

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

Upvotes: 0

Reettik Goswami
Reettik Goswami

Reputation: 9

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

yarn policies set-version

Upvotes: 0

alfred carro
alfred carro

Reputation: 17

yarn policies set-version

this upgraded my yarn version from 1.22.5 to 1.22.10

Upvotes: 0

sonlexqt
sonlexqt

Reputation: 6469

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

Upvotes: 272

NearHuscarl
NearHuscarl

Reputation: 81803

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.

Upvotes: 6

SachinT
SachinT

Reputation: 99

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

Upvotes: 0

SandroMarques
SandroMarques

Reputation: 6554

For Windows users

I usually upgrade Yarn with Chocolatey.

choco upgrade yarn

Upvotes: 39

Abdul Rahman
Abdul Rahman

Reputation: 2029

npm install --global yarn
npm upgrade --global yarn 

This should work.

Upvotes: 197

Chandresh Mishra
Chandresh Mishra

Reputation: 1189

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.

Upvotes: 1

April M. Clements
April M. Clements

Reputation: 517

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

Upvotes: 50

Roshimon
Roshimon

Reputation: 2009

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

Upvotes: 10

random-forest-cat
random-forest-cat

Reputation: 36002

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://stackoverflow.com/a/55278430/1426788 to define my yarn version at the repo level

Upvotes: 19

Stephen
Stephen

Reputation: 1

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

Upvotes: -9

Merabi Pkhaladze
Merabi Pkhaladze

Reputation: 73

  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

Upvotes: 7

Agu V
Agu V

Reputation: 2281

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

Upvotes: 144

Janderson Silva
Janderson Silva

Reputation: 1817

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

Upvotes: 70

Yuriy Rypka
Yuriy Rypka

Reputation: 2107

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.

Upvotes: 23

Related Questions