← 返回命令列表

Linux command

corepack 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Enable Corepack

corepack enable

Disable Corepack

corepack disable

Prepare specific package manager version

corepack prepare [yarn@4.0.0] --activate

Update package.json with package manager

corepack use [pnpm@9.x]

Install from downloaded archive

corepack hydrate [./corepack.tgz]

Pack package manager for offline use

corepack pack [yarn@4.0.0]

说明

corepack is Node.js's package manager manager. It transparently manages Yarn, npm, and pnpm versions per project, using the "packageManager" field in package.json. This ensures that each project uses its specified package manager version without requiring global installations or manual version switching. Included with Node.js from version 14.19.0 to 24.x, Corepack acts as a shim that intercepts package manager commands and automatically downloads and uses the correct version specified in the project's configuration. This eliminates "works on my machine" issues caused by package manager version mismatches across development teams. The tool maintains a local cache of package manager versions and can operate in offline mode using packed archives. Zero runtime dependencies make it lightweight and reliable for CI/CD environments.

参数

--activate
Set as default after preparing

FAQ

What is the corepack command used for?

corepack is Node.js's package manager manager. It transparently manages Yarn, npm, and pnpm versions per project, using the "packageManager" field in package.json. This ensures that each project uses its specified package manager version without requiring global installations or manual version switching. Included with Node.js from version 14.19.0 to 24.x, Corepack acts as a shim that intercepts package manager commands and automatically downloads and uses the correct version specified in the project's configuration. This eliminates "works on my machine" issues caused by package manager version mismatches across development teams. The tool maintains a local cache of package manager versions and can operate in offline mode using packed archives. Zero runtime dependencies make it lightweight and reliable for CI/CD environments.

How do I run a basic corepack example?

Run `corepack enable` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --activate do in corepack?

Set as default after preparing