# Corepack — Node.js Package Manager Version Manager > Corepack is a Node.js tool that manages package manager versions (npm, yarn, pnpm) per project, ensuring every contributor uses the exact same version without manual installs. ## Install Save as a script file and run: # Corepack — Node.js Package Manager Version Manager ## Quick Use ```bash corepack enable corepack prepare pnpm@latest --activate pnpm install ``` ## Introduction Corepack is a zero-install manager for JavaScript package managers that ships with Node.js. It reads the `packageManager` field in `package.json` to automatically download and use the correct version of npm, yarn, or pnpm, eliminating version drift across development teams. ## What Corepack Does - Automatically downloads and caches the correct package manager version specified in package.json - Intercepts calls to yarn, pnpm, and npm to transparently shim the correct binary - Enforces version consistency across all contributors without requiring manual installs - Supports pinning exact package manager versions per project via the packageManager field - Ships with Node.js 16.9+ and requires only a one-time `corepack enable` to activate ## Architecture Overview Corepack installs lightweight shim scripts for each supported package manager in the Node.js bin directory. When you run `yarn` or `pnpm`, the shim reads `packageManager` from the nearest `package.json`, downloads that exact version to a local cache if missing, and forwards the command. The cache is shared across projects, so identical versions are downloaded only once. ## Self-Hosting & Configuration - Enable with `corepack enable` (may require sudo on system Node.js installs) - Add to package.json: `"packageManager": "pnpm@9.1.0"` to pin the version - Use `corepack prepare pnpm@9.1.0 --activate` to pre-download and set a default - Set `COREPACK_HOME` environment variable to customize the cache directory - In CI, run `corepack enable` before `npm install` or `yarn install` for consistent builds ## Key Features - Ships with Node.js out of the box, no additional installation required - Transparent shimming means existing scripts and CI pipelines work without changes - Supports npm, yarn (Classic and Berry), and pnpm with automatic version resolution - Offline-capable once versions are cached; useful for air-gapped environments - Hash verification ensures downloaded package managers match expected checksums ## Comparison with Similar Tools - **nvm / fnm** — Manage Node.js versions; Corepack manages package manager versions within a Node.js install - **volta** — Manages both Node.js and package manager versions; Corepack is lighter and ships with Node.js - **asdf / mise** — General version managers for multiple tools; Corepack is Node.js-specific and zero-install - **npx** — Runs packages without installing; Corepack pins and caches the package manager itself - **ni** — Smart package manager dispatcher; Corepack ensures version consistency rather than just detecting which manager to use ## FAQ **Q: Is Corepack enabled by default in Node.js?** A: Corepack ships with Node.js 16.9+ but is not enabled by default. Run `corepack enable` once to activate the shims. **Q: Does Corepack manage npm versions?** A: Corepack can manage npm versions when specified in `packageManager`, but npm management is opt-in since npm already ships with Node.js. **Q: What happens if the specified version is not cached?** A: Corepack downloads it automatically on first use and caches it for subsequent runs. **Q: Can I use Corepack in Docker builds?** A: Yes. Add `RUN corepack enable` in your Dockerfile before running package install commands. In Node.js 20+ images, Corepack is already present. ## Sources - https://github.com/nodejs/corepack - https://nodejs.org/api/corepack.html --- Source: https://tokrepo.com/en/workflows/asset-aa43e0ab Author: Script Depot