How to install latest yarn version

Muneer Syed
2 min readDec 24, 2023

--

To install the latest version of yarn4.x we need nodejs to be installed first and yarn1.x version

yarn

Nodejs Installation Instructions

Ubuntu:

  1. Import nodesource GPG key
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg - dearmor -o /etc/apt/keyrings/nodesource.gpg

2. Add nodejs deb URL to the sources list

NODE_MAJOR=21
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

`NODE_MAJOR` can be changed depending on the version you need.

NODE_MAJOR=16
NODE_MAJOR=18
NODE_MAJOR=20
NODE_MAJOR=21

3. Now run apt-get update and install nodejs

sudo apt-get update
sudo apt-get install nodejs -y

Uninstall:

sudo apt-get purge nodejs
rm -r /etc/apt/sources.list.d/nodesource.list
rm -r /etc/apt/keyrings/nodesource.gpg

Mac:

Install:

brew install node

Uninstall:

brew uninstall node

Yarn1.x Installation Instructions

Ubuntu:

  1. Import yarn GPG key
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

2. Add yarn deb URL to the sources list

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

3. Now run apt-get update and install yarn

sudo apt-get update
sudo apt-get install --no-install-recommends yarn -y

We don’t want apt-get to install nodejs again as we already installed the latest version of nodejs from the above method, so we are specifying — no-install-recommends in apt-get to not install nodejs along with yarn.

Uninstall:

sudo apt-get purge yarn
rm -r /etc/apt/sources.list.d/yarn.list

Install:

brew install yarn

Uninstall:

brew uninstall yarn

Yarn4.x Installation Instructions

After following the above methods we assume that yarn1.x binary is added to your path, if not run the following command to add it to your path

corepack enable

If corepack is not installed already use npm to install it globally

npm install -g corepack

Now we have to create a project directory and switch to that directory

mkdir yarn-project
cd yarn-project

Initialize the project to use the latest version of yarn

yarn init -2

If you want to update yarn to the latest version you need to run:

yarn set version stable
yarn install

Now yarn will be configured to use the most recent stable binary

Yarn will periodically gather anonymous telemetry to disable it run

yarn config set --home enableTelemetry 0

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Muneer Syed
Muneer Syed

No responses yet

Write a response