While Corepack manages package manager binaries on a per-project basis and doesn't install Yarn globally in the traditional sense, you might need to uninstall global installations of Yarn that were previously installed via other methods like npm or Homebrew. This is often done to ensure Corepack can manage versions without conflicts, or simply to clean up old installations.
The most common ways to uninstall Yarn involve removing its global installation from your system.
Uninstalling Yarn Installed via npm
If you installed Yarn globally using Node.js's package manager, npm, you can uninstall it using the following command:
npm uninstall -g yarn pnpm
Reference Information: In general, you'd do this by running the following command: npm uninstall -g yarn pnpm
This command attempts to uninstall both yarn
and pnpm
globally.
Uninstalling Yarn Installed via Homebrew
If you installed Yarn using the Homebrew package manager on macOS or Linux, you would use a different command:
brew uninstall yarn
Reference Information: That should be enough, but if you installed Yarn without going through npm it might # be more tedious - for example, you might need to run `brew uninstall yarn` as well.
Why Uninstall Global Yarn When Using Corepack?
Corepack works by detecting the packageManager
field in your project's package.json
file and using the specified version of Yarn (or other manager) for that project. Having a globally installed version of Yarn can sometimes lead to confusion or unexpected behavior, although Corepack is designed to override global installations. Cleaning up old global installs ensures a cleaner environment for Corepack to operate in.
Other Potential Uninstall Methods
Depending on how Yarn was initially installed on your system, other methods might be necessary. These could include:
- Using a specific installer's uninstall option.
- Manually removing Yarn files from system directories (less common and not recommended unless you know exactly what you're doing).
In most cases, the npm
or brew
methods mentioned above will cover the primary ways Yarn is installed globally and needs to be uninstalled.