C.W.K.
Stream
Lesson 02 of 05 · published

Install Yarn Berry (per-project, via Corepack)

~9 min · yarn, installation, corepack

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

Yarn Berry doesn't install globally the way npm or pnpm do. The recommended path is Corepack — Node.js's official package-manager-version-manager — which installs Yarn per-project at exactly the version pinned in package.json's packageManager field. That eliminates 'I have v3, you have v4, our lockfiles diverge' problems.

corepack enable activates the shim. The first time you run yarn in a project that has a packageManager field, Corepack downloads that exact yarn version. yarn init -2 bootstraps a new Berry project (the -2 means 'use Yarn 2+', which today means Berry v4). yarn set version stable switches an existing project to the latest stable Berry.

For one-off use without a project, corepack prepare yarn@stable --activate installs the latest yarn globally — useful for running yarn outside a project, but unusual for daily work.

Code

Bootstrap a Berry project·bash
# 1. Enable Corepack (one time per machine)
corepack enable

# 2. Create a new project with Yarn Berry
mkdir my-app && cd my-app
yarn init -2

# 3. The project now has:
#    package.json with "packageManager": "yarn@4.x.x"
#    .yarn/releases/yarn-4.x.x.cjs (the yarn binary, committed)
#    .yarnrc.yml (yarn config)
Migrate an existing project to Berry·bash
# In an existing project, switch to latest stable Berry
yarn set version stable

# Then install
yarn install

# Yarn writes .yarn/cache/, .pnp.cjs, .yarnrc.yml — commit them all
# (yes, even .yarn/cache if you want zero-installs)

External links

Exercise

Bootstrap a scratch Berry project with 'corepack enable && mkdir scratch && cd scratch && yarn init -2'. Look at the .yarn/ directory — see the binary that got committed, the cache structure, the yarnrc. Berry's 'install yourself into the repo' approach is unusual; understanding it unlocks the rest of the model.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.