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.