Reinstall Yarn Safely · Windows · macOS · Linux

Reinstall Yarn Safely, Without Losing Your Project

If Yarn stops working, displays the wrong version, or fails to install your project's dependencies, reinstalling it may seem like the fastest solution.

However, not every Yarn error requires reinstalling the package manager. Sometimes the problem is a missing Corepack command shim. Other times, the package manager works correctly, but a project's dependencies, cache, lockfile, or configuration need attention.

The safest way to reinstall Yarn is to identify what's broken first, preserve the project's configuration, and repair only the affected component.

~/projects/my-app — yarn recovery
$ yarn --version
yarn: command not found

$ corepack --version
0.36.0

$ corepack enable yarn
✓ Done

$ yarn --version
3.6.4

$ corepack install
✓ Done

$ yarn install
✓ Done in 2.34s
Do You Need to Reinstall?

Do you need to reinstall Yarn?

Before changing your installation, determine whether the problem affects Yarn itself or the dependencies of a particular project. These are different issues.

Reinstalling the Yarn Package Manager

Repair or replace the Yarn executable when the terminal cannot find yarn, a global installation conflicts with Corepack, or the active version is wrong.

Reinstalling Project Dependencies

For missing or incomplete project dependencies, start with a normal install. You do not need to reinstall Yarn itself.

Terminal / Code
yarn install
Protect Your Project

Before reinstalling Yarn: protect your project

A Yarn repair should not require deleting unrelated source files or configuration. Protect the files that define your application dependencies and tooling.

Check for Uncommitted Changes

Review uncommitted changes and back up important work before making changes.

Terminal / Code
git status

Preserve Important Files

Do not delete these files without understanding how the repository uses them.

Terminal / Code
package.json
yarn.lock
.yarnrc.yml
.yarnrc
.npmrc
.pnp.cjs
.yarn/releases/
.yarn/plugins/
.yarn/patches/

Record Your Current Versions

Note exact command errors and version numbers.

Terminal / Code
node --version
npm --version
yarn --version
corepack --version
Reinstall With Corepack

How to reinstall Yarn with Corepack

For modern Yarn projects, Corepack is the recommended version-management approach. It lets each project declare its expected Yarn version.

Check Your Node.js Version

Corepack compatibility depends on the installed Node.js release.

Terminal / Code
node --version

Verify Corepack

If missing, install a Corepack release compatible with your Node.js version.

Terminal / Code
corepack --version
npm install -g corepack

Restore the Yarn Command Shim

This requests the Yarn command shim without changing dependency declarations.

Terminal / Code
corepack enable yarn

Check the Active Yarn Version

Check the version configured for the project.

Terminal / Code
yarn --version

Prepare the Project’s Yarn Version

Run from the project root.

Terminal / Code
corepack install

Install Project Dependencies If Necessary

Modern Yarn can use --immutable; Yarn Classic uses --frozen-lockfile.

Terminal / Code
yarn install
yarn install --immutable
yarn install --frozen-lockfile
Reinstall on Windows

How to reinstall Yarn on Windows 10 and Windows 11

Windows may have conflicts between npm-installed Yarn, Corepack shims and Node.js installer components.

Open PowerShell

Check installed tools.

Terminal / Code
node --version
corepack --version

Locate Yarn

Look for unexpected locations or multiple launchers.

Terminal / Code
Get-Command yarn -All

Restore the Corepack Yarn Shim

Restore and verify the command.

Terminal / Code
corepack enable yarn
yarn --version

Check PowerShell Launcher Issues

If a .ps1 launcher is blocked, test the matching .cmd launcher.

Terminal / Code
yarn.cmd --version

Investigate Existing Global Installations

Remove npm-managed Yarn only after confirming a conflict.

Terminal / Code
npm uninstall -g yarn
corepack enable yarn
Reinstall on macOS

How to reinstall Yarn on macOS

Yarn may have been installed through Corepack, npm, Homebrew or another development tool.

Identify the Active Yarn Command

Inspect matching commands.

Terminal / Code
command -v yarn
type -a yarn

Check Corepack

Restore and verify the shim.

Terminal / Code
corepack --version
corepack enable yarn
yarn --version

Review npm or Homebrew Conflicts

Only remove an installation once its source has been confirmed.

Terminal / Code
npm uninstall -g yarn
brew list --versions yarn
brew uninstall yarn

Restore Corepack-Managed Yarn

Check that the project version matches.

Terminal / Code
corepack enable yarn
yarn --version

What If macOS Reports Permission Denied?

Avoid broad directory permission changes; check where Corepack is installed.

Terminal / Code
command -v corepack
Reinstall on Linux

How to reinstall Yarn on Linux

Identify whether Yarn comes from Corepack, npm, a distribution package manager or a manual executable.

Check Installed Tools

Check versions and executable locations.

Terminal / Code
node --version
corepack --version
command -v yarn
type -a yarn

Restore Corepack Shims

Verify the Yarn version.

Terminal / Code
corepack enable yarn
yarn --version

Investigate Global Conflicts

Only remove npm-managed Yarn after confirming the conflict.

Terminal / Code
npm uninstall -g yarn
corepack enable yarn

Check PATH and Permissions

Check where commands resolve.

Terminal / Code
command -v corepack
command -v yarn
Reinstall Yarn Classic

How to reinstall Yarn Classic (Yarn 1)

For a legacy project requiring Yarn 1, determine whether Yarn is managed through Corepack or installed globally.

Reinstall a Standalone Yarn Classic Installation

Use this only when you intentionally want a standalone Yarn Classic installation.

Terminal / Code
npm uninstall -g yarn
npm install -g yarn@1
yarn --version

Restore Yarn Classic Through Corepack

Preserve the configured version in package.json.

Terminal / Code
{
  "packageManager": "[email protected]"
}
corepack install
yarn --version
Reinstall node_modules

How to reinstall node_modules with Yarn

If Yarn works but project dependencies are missing, the package manager usually does not need to be reinstalled.

Check the Project

Confirm package.json and the lockfile are present.

Terminal / Code
cd your-project

Check Yarn

Verify Yarn is accessible.

Terminal / Code
yarn --version

Run a Normal Installation

A normal install may repair dependencies without deleting node_modules.

Terminal / Code
yarn install

What If You Need a Fresh Dependency Installation?

For Yarn Classic, --force refetches packages. Modern Yarn should begin with a normal install.

Terminal / Code
yarn install --force
yarn install

Should You Delete node_modules?

Only with a specific reason after verifying the directory. Deletion will not fix version, registry, or build-script errors.

Why node_modules Is Missing

Yarn Plug’n’Play: why node_modules may be missing

Modern Yarn can use Plug’n’Play instead of a traditional node_modules directory.

Check the Dependency Linker

If nodeLinker reports pnp, missing node_modules may be expected.

Terminal / Code
yarn config get nodeLinker

What If the Project Requires node_modules?

Changing the linker affects project configuration; preserve the existing setup unless necessary.

Terminal / Code
yarn config set nodeLinker node-modules
yarn install
Clear the Yarn Cache

How to clear the Yarn cache safely

Different Yarn generations have different cache-management options. Clearing the cache should not be the first response to every failure.

Yarn Classic Cache

Inspect the cache location before clearing it.

Terminal / Code
yarn cache dir
yarn cache clean

Modern Yarn Cache

Inspect the current cache configuration.

Terminal / Code
yarn config get cacheFolder
yarn config get enableGlobalCache
yarn cache clean

Check Package Integrity Before Clearing the Cache

Use supported cache checks to investigate integrity mismatches.

Terminal / Code
yarn install --check-cache
Clear the Corepack Cache

How to clear the Corepack cache

Corepack caches package manager releases separately from Yarn application dependencies.

Clear the Corepack Cache

Only clear this when you have confirmed a Corepack cache problem.

Terminal / Code
corepack cache clean

When Should You Clear the Corepack Cache?

Consider corrupted package-manager downloads or incomplete cached releases. Ensure you can restore the release in offline environments.

Fix Version Conflicts

How to fix Corepack and Yarn version conflicts

Multiple Yarn installations can cause the terminal to run the wrong release.

Check the Project’s Expected Version

Inspect the packageManager field.

Terminal / Code
{
  "packageManager": "[email protected]"
}

Check the Active Version

Compare the active version.

Terminal / Code
yarn --version

Locate the Executable

Check all matching executables.

Terminal / Code
type -a yarn
Get-Command yarn -All

Review yarnPath

Check whether a local release file is configured.

Terminal / Code
yarnPath: .yarn/releases/yarn-3.6.4.cjs

Restore the Intended Setup

Restore Corepack and prepare the project version.

Terminal / Code
corepack enable yarn
corepack install
yarn --version
Common Errors

Fixing common Yarn reinstallation errors

Use the exact error message to decide which part of the environment needs repair.

1. yarn: command not found

Check whether Corepack is available and the Yarn shim is enabled.

Terminal / Code
corepack --version
corepack enable yarn

2. Permission denied / EACCES / EPERM

Inspect the affected path and ownership. Avoid blanket permission changes.

3. Wrong Yarn version

Check packageManager, yarnPath and the executable resolved by PATH.

Terminal / Code
yarn --version

4. Network or registry errors

Check network connectivity, configured registries and credentials.

5. Lockfile or checksum errors

Investigate dependency declarations and integrity rather than deleting project files.

Without Losing Lockfile

How to reinstall Yarn without losing your lockfile

Preserve yarn.lock and project configuration. Avoid deleting the lockfile as a first troubleshooting step.

Check the Lockfile

Review changes before and after installation.

Terminal / Code
git status

Use the Appropriate Immutable Installation

Choose the flag that matches the Yarn generation.

Terminal / Code
yarn install --immutable
yarn install --frozen-lockfile
CI/CD and Docker

Reinstall Yarn in CI/CD and Docker

Automated environments should use reproducible package-manager versions and dependency installs.

Pin the Project Package Manager

Use the project’s packageManager declaration and a compatible Corepack version.

Terminal / Code
corepack enable yarn
corepack install

Use Reproducible Installs

Keep the lockfile and use the appropriate immutable installation mode.

Terminal / Code
yarn install --immutable
Reinstall vs. Update

Reinstall Yarn vs. update Yarn

Reinstalling repairs an existing installation. Updating intentionally changes the Yarn version.

Reinstall

Restore the version already expected by the project.

Terminal / Code
corepack install

Update

Only change the project version when you intend to upgrade and have tested compatibility.

Best Practices

Yarn reinstallation best practices

Keep changes targeted, preserve project configuration and verify the active package-manager version.

Protect Important Files

Keep package.json, yarn.lock and Yarn configuration under version control.

Diagnose Before Deleting

Check PATH, Corepack, linkers and caches before removing generated directories.

Verify After Repair

Run the appropriate project commands and review the resulting changes.

Terminal / Code
yarn --version
yarn install
FAQ

Frequently asked questions

Answers to common questions about repairing Yarn installations.

Do I need to uninstall Yarn before reinstalling?

Not usually. Identify whether the problem is the command shim, package manager or project dependencies.

Will reinstalling Yarn delete yarn.lock?

It should not require deleting the lockfile. Preserve and review it.

Why is node_modules missing after yarn install?

The project may use Plug’n’Play instead of the node-modules linker.

Can I use Corepack with Yarn Classic?

Yes, compatible Corepack versions can select a project-declared Yarn Classic release.

Scroll to Top