Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I upgrade legacy yarn(1.22.x) to yarn 4.x globally?

Tags:

yarnpkg-v4

As far as I know, npm install -g yarn or sudo apt install yarn installs the legacy yarn version which is 1.22.x. If you want to migrate to yarn 4.x for a specific project, it is possible using yarn set version stable (or replace stable with the specific version to upgrade to). However, my use case required installing yarn 4.x globally as opposed to per project(which I know is discouraged in general) and I could not find any information on how to do that.

like image 348
Naomikho Avatar asked Feb 04 '26 15:02

Naomikho


2 Answers

I managed to install yarn 4.x globally using Mise, a tool for configuring development environments.

  1. Install mise
  2. mise use [email protected]
  3. mise use [email protected]

After this, using yarn -v should show the correct version. Because I was using phpstorm, it only executes yarn from /bin/yarn, so I had to use a symlink to make it work.

  1. sudo ln -s /home/naomi/.local/share/mise/installs/yarn/4.2.1/bin/yarn /bin/yarn (replace the first path with where your yarn is installed. You can check the path using which yarn)
  2. ls -l /bin/yarn (ensure symlink is working)
  3. yarn -v (ensure yarn is working after symlink is established)
like image 148
Naomikho Avatar answered Feb 06 '26 11:02

Naomikho


Stop installing yarn globally, use per-project yarn instead.

This allows migration per project.

Installing yarn by corepack enable is now the recommended way:

https://yarnpkg.com/migration/guide

like image 23
MKesper Avatar answered Feb 06 '26 12:02

MKesper