How to Install Yarn on Debian (13, 12, 11)

Last updated Monday, February 9, 2026 9:46 am Joshua James 11 min read

This guide walks through how to install Yarn on Debian 13, 12, and 11 using Corepack, Node.js’s built-in package manager tool, with Debian’s default repositories as an alternative on Debian 13. Yarn handles project dependencies with parallel downloads, offline caching, and deterministic lockfiles, making it a reliable choice for React applications, Node.js backend projects, and modern JavaScript toolchains. By the end of this guide, you will have Yarn Berry 4.x installed and configured with per-project version control, ready for production JavaScript development.

Install Yarn on Debian

Yarn has two major release lines: Yarn Classic (1.x), which has been in maintenance mode since January 2020 and only receives critical security fixes, and Yarn Berry (2.x through 4.x), the actively developed version recommended by the Yarn team. The official Yarn Classic repository describes the 1.x line as frozen, with active development now happening in the Yarn Berry repository. This guide focuses exclusively on Yarn Berry installed via Corepack, the officially recommended method.

Two methods provide modern Yarn Berry on Debian, and the comparison table below outlines each method’s trade-offs.

MethodChannelVersionUpdatesBest For
Corepack (Recommended)Yarn OfficialLatest stable (4.12.0+)Manual via corepack prepareAll users: official method with per-project version control
Debian ReposDebian PackagesDistro stable (4.1.0)Automatic via apt upgradeDebian 13 users wanting distro-managed packages

For most users, the Corepack method is recommended because it’s officially endorsed by the Yarn team, provides per-project version control via the packageManager field in package.json, and works across all Debian versions. The Debian repository method is only viable on Debian 13, which ships Yarn Berry 4.x. In contrast, Debian 11 and 12 ship the legacy Classic version (1.x), which is no longer recommended for new projects.

These instructions apply to Debian 13 (Trixie), Debian 12 (Bookworm), and Debian 11 (Bullseye). Debian 13 includes Corepack in the default Node.js package, while Debian 11 and 12 require NodeSource for a Node.js version that ships Corepack. Steps remain consistent across all three releases unless noted otherwise.

Install via Corepack (Recommended)

Corepack is Node.js’s built-in package manager tool that enables per-project Yarn version control, and this is the officially recommended installation method from the Yarn documentation.

Install Node.js on Debian 13

Debian 13 includes Node.js 20.x with Corepack in the default repositories, so installation is straightforward:

sudo apt update
sudo apt install nodejs

If you need to run commands with sudo and your account is not yet configured, see how to add a user to sudoers on Debian.

Verify that Node.js and Corepack are available:

node --version
corepack --version

You should see output similar to:

v20.19.2
0.24.0

Debian 13’s Node.js 20.x is sufficient for Yarn Berry. If you specifically need Node.js 24.x, you can use the NodeSource instructions in the Debian 11/12 section below.

Install Node.js on Debian 11 or 12

Debian 11 ships Node.js 12.x and Debian 12 ships Node.js 18.x, but neither version includes the Corepack binary required for Yarn Berry installation. Additionally, the yarnpkg packages in both releases are Yarn Classic 1.x, which is in maintenance mode. Therefore, to use the recommended Corepack method, you’ll need to install Node.js LTS from NodeSource.

First, install the prerequisites, including curl for downloading and gpg for key conversion, and create the keyrings directory:

sudo apt update
sudo apt install -y curl gpg
sudo install -m 0755 -d /etc/apt/keyrings

Next, download and import the NodeSource GPG key:

curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Then, create the NodeSource repository configuration:

cat <<EOF | sudo tee /etc/apt/sources.list.d/nodesource.sources
Types: deb
URIs: https://deb.nodesource.com/node_24.x
Suites: nodistro
Components: main
Signed-By: /etc/apt/keyrings/nodesource.gpg
EOF

The nodistro suite is NodeSource’s unified repository that works across all Debian and Ubuntu versions. If you need a different Node.js major version, change node_24.x to node_22.x or node_20.x.

Now, update the package lists and install Node.js:

sudo apt update
sudo apt install -y nodejs

Finally, verify the installation:

node --version
corepack --version

You should see output similar to:

v24.x.x
0.x.x

Enable Corepack and Install Yarn Berry

With Node.js installed, enable Corepack to manage Yarn:

sudo corepack enable

This command runs silently on success, creating the Yarn shim in your system’s Node.js bin directory.

Next, install the latest stable Yarn version globally:

corepack prepare yarn@stable --activate

Finally, verify that Yarn Berry is installed:

yarn --version

The output should display:

4.12.0

Install from Debian Repositories (Debian 13 Only)

Debian 13 ships Yarn Berry 4.x in the default repositories. While this method provides automatic security updates through standard system updates, it lacks the per-project version control that Corepack offers.

This method only works on Debian 13 (Trixie). Debian 11 and 12 ship Yarn Classic 1.x, which is in maintenance mode and not recommended for new projects. If you’re on Debian 11 or 12, use the Corepack method above.

Update your package lists and install Yarn:

sudo apt update
sudo apt install yarnpkg

Next, verify the installation:

yarnpkg --version

The output should show:

4.1.0

The package is named yarnpkg (not yarn) in Debian repositories to avoid conflicts with an unrelated package. After installation, run commands using yarnpkg instead of yarn, or create a symlink for convenience.

Create a Yarn Command Symlink

For convenience, to use the standard yarn command instead of yarnpkg, create a symbolic link:

sudo ln -s /usr/bin/yarnpkg /usr/local/bin/yarn

Once created, you can use yarn directly:

yarn --version

Essential Yarn Berry Commands on Debian

Yarn Berry introduces several improvements over Classic that change how you interact with the package manager. The syntax differs in key areas: yarn up replaces yarn upgrade, and yarn dlx replaces the need for globally installed CLI tools. The following sections cover the commands you’ll use most frequently, organized by workflow. For complete documentation, see the official Yarn CLI reference.

If you installed Yarn from Debian repositories (the yarnpkg package), the command is yarnpkg instead of yarn. You can either use yarnpkg in all examples below, or create the symlink shown earlier to use the standard yarn command.

Initialize a Project

Proper initialization ensures consistent behavior across your team’s machines by pinning Yarn’s version in the project. Create a new project with Yarn Berry using:

yarn init -2

The -2 flag explicitly initializes a Yarn Berry project rather than falling back to Classic. As a result, this command creates a package.json with a packageManager field that pins the Yarn version for the project:

{
  "name": "my-project",
  "packageManager": "yarn@4.x.x"
}

Alternatively, for an interactive setup with prompts:

yarn init

Set Yarn Version Per-Project

Pinning a specific Yarn version ensures everyone on the team uses the same release. Use the stable channel to get the latest production-ready version:

yarn set version stable

Alternatively, specify an exact version:

yarn set version 4.5.0

Either approach downloads Yarn to .yarn/releases/ and updates the packageManager field in package.json. This ensures all team members use the same Yarn version when they clone the repository. Configuration settings are stored in .yarnrc.yml at the project root.

Manage Dependencies

Dependency management is where you’ll spend most of your time with Yarn. Understanding the difference between production and development dependencies helps keep your deployed applications lean. Production dependencies ship with your app, while development dependencies only assist during development.

Adding a production dependency is straightforward:

yarn add lodash

Development-only dependencies use the -D flag, which prevents them from shipping with production builds:

yarn add -D eslint

Removing a package works similarly:

yarn remove lodash

When cloning a project or restoring dependencies, install all packages from the existing package.json:

yarn install

Or use the shorthand form:

yarn

Update Dependencies

Keeping dependencies updated is essential for security patches and new features, but updates can also introduce breaking changes. Yarn Berry provides tools to review updates before applying them, which is especially important in production projects.

Upgrading a specific package to its latest version requires the up command:

yarn up lodash

Interactive mode lets you review each update before applying it, which is useful for catching breaking changes:

yarn up --interactive

If you want to update all packages at once instead, use the wildcard pattern:

yarn up '*'

Run Scripts

Scripts defined in your package.json run through Yarn’s script runner:

yarn run build
yarn run test

Common scripts like build, test, and start work without the explicit run keyword:

yarn build
yarn test
yarn start

Run Binaries with dlx

The dlx command lets you run packages without installing them globally, similar to npm’s npx. This is useful for project scaffolding tools and one-off commands:

yarn dlx create-react-app my-app
yarn dlx degit user/repo my-project

Workspace Commands

Workspaces let you manage multiple related packages in a single repository, commonly called a monorepo. This approach is popular for organizations maintaining shared component libraries or microservices that need to stay in sync. Yarn Berry includes built-in monorepo support through its workspace commands.

Running a command in a specific workspace uses the following syntax:

yarn workspace my-package build

Executing a command across all workspaces requires the foreach subcommand:

yarn workspaces foreach run build

Plug’n’Play Mode

By default, Yarn Berry uses Plug’n’Play (PnP), which eliminates the node_modules folder entirely. Instead of thousands of nested folders, PnP uses a single .pnp.cjs file that maps imports directly to zip archives in .yarn/cache/. This approach dramatically speeds up installs and reduces disk usage. The main PnP files in your project are:

  • .pnp.cjs – The module resolution map (this is what Node uses to find packages)
  • .yarn/cache/ – Zipped package archives
  • .yarnrc.yml – Project-level Yarn configuration

However, some packages may not work correctly with PnP, particularly older ones or those that make assumptions about node_modules structure. If you encounter compatibility issues, you can switch to the traditional node_modules mode:

yarn config set nodeLinker node-modules
yarn install

Later, to switch back to PnP:

yarn config set nodeLinker pnp
yarn install

Troubleshoot Common Yarn Issues on Debian

Even after a successful installation, you may encounter configuration issues that prevent Yarn from working correctly. Most problems stem from Node.js version mismatches, permission conflicts, or PnP compatibility with certain packages. The following sections cover the most common problems and their solutions based on issues frequently reported in the Yarn community.

Corepack Not Found

If you see this error:

bash: corepack: command not found

This error means your Node.js version is too old (Corepack requires Node.js 16.10+). To diagnose, first check your version:

node --version

If the output shows a version below v16.10, install a modern Node.js version using NodeSource as shown in the installation section.

PnP Compatibility Issues

Some packages don’t work correctly with Plug’n’Play. This is particularly true for native modules, packages that scan node_modules at runtime, or older packages that haven’t been updated for PnP compatibility. If you see errors like:

Error: Cannot find module 'some-package'

This error typically indicates the package expects a traditional node_modules structure. To resolve this issue, switch to node_modules linker mode:

yarn config set nodeLinker node-modules
yarn install

Afterward, verify the change:

yarn config get nodeLinker

The output confirms the setting:

node-modules

Permission Errors

If you see permission errors when enabling Corepack:

EACCES: permission denied

Running Corepack with sudo resolves this issue since it needs to write to system directories:

sudo corepack enable

yarn Command Not Found (Debian Repos)

If you installed Yarn from Debian repositories and see “command not found” when running yarn, remember the package name is yarnpkg. Create the symlink shown earlier or use yarnpkg directly.

Remove Yarn from Debian

Should you need to uninstall Yarn, whether to switch installation methods or troubleshoot conflicts, use the method corresponding to how you originally installed it. Mixing removal methods can leave orphaned files or broken symlinks.

Disable Yarn in Corepack

Disabling the Yarn shim removes it from Corepack without affecting other package managers:

sudo corepack disable yarn

Verify the removal by checking if the command is still available:

yarn --version

The expected output confirms that Yarn is no longer available:

bash: yarn: command not found

Remove NodeSource Repository (If Added)

If you added the NodeSource repository for Debian 11 or 12 and no longer need it, remove the repository configuration and GPG key:

sudo rm /etc/apt/sources.list.d/nodesource.sources
sudo rm /etc/apt/keyrings/nodesource.gpg
sudo apt update

Once removed, the system will use Debian’s default Node.js version for future installations.

Remove Yarn Installed from Debian Repositories

To remove Yarn installed via APT, run:

sudo apt remove --purge yarnpkg
sudo apt autoremove

Additionally, remove the symlink if you created one:

sudo rm /usr/local/bin/yarn

Confirm the symlink was removed:

ls -l /usr/local/bin/yarn

You should see:

ls: cannot access '/usr/local/bin/yarn': No such file or directory

Next, verify the APT package removal:

dpkg -l yarnpkg

The expected output confirms the package was removed:

dpkg-query: no packages found matching yarnpkg

Remove Yarn Configuration and Cache

The following commands permanently delete Yarn’s configuration and cached packages. Back up any configuration you want to keep first.

rm -rf ~/.yarn ~/.yarnrc.yml

FAQ on Installing Yarn on Debian

Does Yarn Berry work differently from Yarn Classic?

Yes. Yarn Berry (2.x and later) uses a different architecture from Yarn Classic (1.x). Berry stores its own release binary inside each project under .yarn/releases/, resolves dependencies using Plug’n’Play by default instead of node_modules, and locks its version per-project through the packageManager field in package.json. Classic used a single global installation and always created a node_modules directory. Projects written for Classic may need nodeLinker set to node-modules in .yarnrc.yml to work under Berry.

Can Yarn and npm coexist on the same Debian system?

Yes. Yarn and npm are independent package managers that do not conflict. Node.js ships with npm, and Corepack manages Yarn separately. You can use npm in one project and Yarn in another without any issues. The packageManager field in each project’s package.json tells Corepack which manager to activate.

What is Corepack and why does Yarn recommend it?

Corepack is a tool bundled with Node.js that manages package manager binaries like Yarn and pnpm. Instead of installing Yarn globally, Corepack downloads the exact version each project specifies in its packageManager field. This prevents version mismatches across machines and CI environments, which is why the Yarn team recommends it as the primary installation method.

Conclusion

You now have Yarn Berry installed on Debian via Corepack. Pin versions per-project with yarn set version stable, scaffold new projects using yarn init -2, and run one-off tools through yarn dlx. To expand your development environment, consider installing Git on Debian, setting up Visual Studio Code, or installing Docker on Debian for containerized builds.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<a href="URL">link</a> link
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: