Yarn is a JavaScript package manager used to install a project’s dependencies. This guide sets it up on Linux or macOS using Corepack, which selects the Yarn version specified by each project.

Check Node.js and npm

Use a maintained Node.js release supported by your project. In a terminal, run:

node --version
npm --version

If either command is missing, install Node.js using a supported method for your operating system. A user-managed Node.js installation avoids needing administrator access for global npm packages.

Install and enable Corepack

Corepack is not included with every Node.js distribution. Install it through npm, then enable its package manager commands:

npm install -g corepack
corepack enable

These commands need write access to your Node.js installation. If that installation is administrator-managed, use its approved installation process rather than changing system ownership to bypass permissions.

Use Yarn in a project

For an existing project, open its directory and check the packageManager setting in package.json. Keep the project’s declared version unless you are deliberately upgrading it.

yarn --version

To create a new project, open an empty directory and run:

yarn init -2
yarn --version

Initialisation creates project files. For an existing project, do not run it simply to check whether Yarn is installed.

Yarn is separate from Hadoop’s YARN resource manager. Installing the global yarn npm package follows the older Yarn Classic workflow; it is not the current project-specific setup described here.