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.
$ 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 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.
yarn installBefore 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.
git statusPreserve Important Files
Do not delete these files without understanding how the repository uses them.
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.
node --version
npm --version
yarn --version
corepack --versionHow 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.
node --versionVerify Corepack
If missing, install a Corepack release compatible with your Node.js version.
corepack --version
npm install -g corepackRestore the Yarn Command Shim
This requests the Yarn command shim without changing dependency declarations.
corepack enable yarnCheck the Active Yarn Version
Check the version configured for the project.
yarn --versionPrepare the Project’s Yarn Version
Run from the project root.
corepack installInstall Project Dependencies If Necessary
Modern Yarn can use --immutable; Yarn Classic uses --frozen-lockfile.
yarn install
yarn install --immutable
yarn install --frozen-lockfileHow 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.
node --version
corepack --versionLocate Yarn
Look for unexpected locations or multiple launchers.
Get-Command yarn -AllRestore the Corepack Yarn Shim
Restore and verify the command.
corepack enable yarn
yarn --versionCheck PowerShell Launcher Issues
If a .ps1 launcher is blocked, test the matching .cmd launcher.
yarn.cmd --versionInvestigate Existing Global Installations
Remove npm-managed Yarn only after confirming a conflict.
npm uninstall -g yarn
corepack enable yarnHow 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.
command -v yarn
type -a yarnCheck Corepack
Restore and verify the shim.
corepack --version
corepack enable yarn
yarn --versionReview npm or Homebrew Conflicts
Only remove an installation once its source has been confirmed.
npm uninstall -g yarn
brew list --versions yarn
brew uninstall yarnRestore Corepack-Managed Yarn
Check that the project version matches.
corepack enable yarn
yarn --versionWhat If macOS Reports Permission Denied?
Avoid broad directory permission changes; check where Corepack is installed.
command -v corepackHow 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.
node --version
corepack --version
command -v yarn
type -a yarnRestore Corepack Shims
Verify the Yarn version.
corepack enable yarn
yarn --versionInvestigate Global Conflicts
Only remove npm-managed Yarn after confirming the conflict.
npm uninstall -g yarn
corepack enable yarnCheck PATH and Permissions
Check where commands resolve.
command -v corepack
command -v yarnHow 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.
npm uninstall -g yarn
npm install -g yarn@1
yarn --versionRestore Yarn Classic Through Corepack
Preserve the configured version in package.json.
{
"packageManager": "[email protected]"
}
corepack install
yarn --versionHow 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.
cd your-projectCheck Yarn
Verify Yarn is accessible.
yarn --versionRun a Normal Installation
A normal install may repair dependencies without deleting node_modules.
yarn installWhat If You Need a Fresh Dependency Installation?
For Yarn Classic, --force refetches packages. Modern Yarn should begin with a normal install.
yarn install --force
yarn installShould You Delete node_modules?
Only with a specific reason after verifying the directory. Deletion will not fix version, registry, or build-script errors.
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.
yarn config get nodeLinkerWhat If the Project Requires node_modules?
Changing the linker affects project configuration; preserve the existing setup unless necessary.
yarn config set nodeLinker node-modules
yarn installHow 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.
yarn cache dir
yarn cache cleanModern Yarn Cache
Inspect the current cache configuration.
yarn config get cacheFolder
yarn config get enableGlobalCache
yarn cache cleanCheck Package Integrity Before Clearing the Cache
Use supported cache checks to investigate integrity mismatches.
yarn install --check-cacheHow 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.
corepack cache cleanWhen Should You Clear the Corepack Cache?
Consider corrupted package-manager downloads or incomplete cached releases. Ensure you can restore the release in offline environments.
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.
{
"packageManager": "[email protected]"
}Check the Active Version
Compare the active version.
yarn --versionLocate the Executable
Check all matching executables.
type -a yarn
Get-Command yarn -AllReview yarnPath
Check whether a local release file is configured.
yarnPath: .yarn/releases/yarn-3.6.4.cjsRestore the Intended Setup
Restore Corepack and prepare the project version.
corepack enable yarn
corepack install
yarn --versionFixing 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.
corepack --version
corepack enable yarn2. 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.
yarn --version4. 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.
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.
git statusUse the Appropriate Immutable Installation
Choose the flag that matches the Yarn generation.
yarn install --immutable
yarn install --frozen-lockfileReinstall 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.
corepack enable yarn
corepack installUse Reproducible Installs
Keep the lockfile and use the appropriate immutable installation mode.
yarn install --immutableReinstall Yarn vs. update Yarn
Reinstalling repairs an existing installation. Updating intentionally changes the Yarn version.
Reinstall
Restore the version already expected by the project.
corepack installUpdate
Only change the project version when you intend to upgrade and have tested compatibility.
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.
yarn --version
yarn installFrequently 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.