yarn
Yarn 1.x (classic) / Yarn 4 (berry)Quick reference for everyday Yarn CLI commands (both Yarn Classic 1.x and Yarn Berry 2/3/4): install / add / remove / run / workspaces, lockfile, Plug'n'Play, and Berry configuration — with common options and practical examples.
33 commands
Install (Classic 1.x)
yarn installInstall every dependency listed in `package.json`, creating or refreshing `node_modules` and `yarn.lock`.
--frozen-lockfile fail if lock would change (CI); --production / --prod skip devDeps; --no-progress; --silent
yarn install --frozen-lockfileyarn install --frozen-lockfileInstall only if `yarn.lock` matches `package.json` exactly. Used in CI to guarantee reproducible builds.
yarn install --frozen-lockfileInstall (Berry)
yarn installBerry default: uses Plug'n'Play when `nodeLinker: pnp` is in `.yarnrc.yml`, otherwise falls back to `node_modules`. Caches in `.yarn/cache`.
--immutable fail on lockfile drift (Berry equivalent of --frozen-lockfile); --inline-builds; --mode=update-lockfile
yarn install --immutableyarn set version <version>Switch the Yarn binary in the project. Common: `yarn set version stable`, `yarn set version 4.0.2`, `yarn set version classic`.
yarn set version stableAdd dependency
yarn add <pkg>Add a runtime dep and write to `package.json` + lockfile. Classic writes to `dependencies`, Berry same.
<pkg>@<version|range>; --dev / -D; --exact / -E; --optional / -O; --peer
yarn add lodash && yarn add -D typescript@^5 vitestyarn add -D <pkg>Add to `devDependencies`.
yarn add -D typescript @types/node eslintyarn add <pkg>@<version>Install a specific version, dist-tag (`@latest`, `@next`, `@canary`), or git URL.
yarn add [email protected] && yarn add next@latestyarn global add <pkg>Install a tool globally (Classic 1.x). Berry uses `yarn dlx` for one-shot binaries and recommends `corepack` for global tools.
yarn global add typescriptRemove
yarn remove <pkg>Remove a package from `node_modules` and the relevant `dependencies` / `devDependencies` section.
yarn remove lodash && yarn remove -D @types/nodeUpdate
yarn upgradeUpgrade all dependencies within their current semver ranges; `yarn upgrade --latest` jumps to the newest available release and rewrites the range.
--latest; --pattern <glob>; --caret; --exact; -i / --interactive
yarn upgrade && yarn upgrade eslint --latestyarn upgrade <pkg>@<version>Upgrade a single package to a specific version.
yarn upgrade [email protected]Run script
yarn run <script>Run a script from `package.json`. `yarn test`, `yarn start`, `yarn build` are shorthand.
-- <args> forward args to the script
yarn run build -- --mode productionyarn <script>Same as `yarn run <script>` — call any defined script by name without the `run` keyword.
yarn test && yarn lint:fixyarn dlx <pkg> [args]Run a package binary on demand without installing it locally (Berry equivalent of `npx`). Caches to `~/.yarn/berry/cache`.
-p / --package pick package; -q / --quiet
yarn dlx create-vite my-app --template vueWorkspaces
yarn workspaces add <pkg>Add a dependency to the root of a monorepo workspace (1.x).
yarn workspaces add typescript -Dyarn workspace <ws> add <pkg>Add a dep to a single named workspace within the monorepo.
yarn workspace @myorg/web add react && yarn workspace @myorg/api add -D vitestyarn workspaces run <script>Run a script in every workspace. `yarn workspaces foreach run <script>` (Berry) supports concurrency and topology order.
--parallel; --topological; --continue; --interlaced
yarn workspaces foreach run build --topological --parallelInspect
yarn listPrint the dependency tree. `--pattern <regex>` filters; `--depth 0` shows direct deps only.
--depth=N; --pattern; --json
yarn list --depth=0 && yarn list --pattern "^react$"yarn why <pkg>Explain why a given package is installed — the chain of dependencies that brought it in.
yarn why react && yarn why @types/nodeyarn info <pkg>Print registry metadata for a package — versions, dependencies, dist-tags, readme excerpt. Roughly equivalent to `npm view`.
<pkg>@<version>; <pkg> readme; <pkg> dependencies
yarn info react dist-tags && yarn info lodash versionsyarn licenses listList every license across the dependency tree (SPDX identifier + author). Useful for license-compliance reviews.
yarn licenses listBerry configuration
yarn config set <key> <value>Write a config entry to `.yarnrc.yml` (Berry). Common keys: `nodeLinker`, `npmRegistryServer`, `enableTelemetry`, `yarnPath`.
yarn config set nodeLinker node-modules && yarn config set enableTelemetry falseyarn config get <key>Read a single config entry.
yarn config get nodeLinkerCache
yarn cache cleanWipe the Yarn cache (Classic: `~/.yarn-cache`; Berry: `.yarn/cache`).
yarn cache cleanyarn cache dirPrint the cache directory path.
yarn cache dirLockfile
yarn importBerry only — import `package-lock.json` from npm into Yarn's lockfile format.
yarn importyarn constraintsBerry only — enforce project-wide dependency rules written in Prolog in `constraints.pro` (e.g. every workspace must depend on the same React version).
yarn constraintsAudit
yarn npm auditBerry — proxy to the npm registry's advisory feed. Reports vulnerabilities in the lockfile.
--severity info|low|moderate|high|critical; --json
yarn npm audit --severity highMisc
yarn versionPrint the current Yarn version (works for both Classic and Berry).
yarn versionyarn initCreate a `package.json` interactively or with `-y` for defaults.
-y accept defaults; -p / --private mark as private
yarn init -yyarn packBundle the current package into a tarball without publishing — useful for offline distribution.
--filename; --pack-destination <dir>
yarn pack --filename my-pkg.tgzPlug'n'Play (Berry)
yarn unplug <pkg>Extract a single package from the PnP zip store into a normal `node_modules/<pkg>` so it can be required the old-fashioned way (workaround for incompatible tooling).
yarn unplug react && yarn installyarn rebuildRecompile native addons for the current Node ABI. Berry needs this for packages with native deps under PnP.
yarn rebuildRelated command cheatsheets
volta
Quick reference for everyday Volta commands: install Node / npm / Yarn / pnpm toolchains, pin per-project versions, manage global packages, and troubleshoot Volta itself — with common options and practical examples.
25 commands
Volta 1.x
npm
Quick reference for everyday npm CLI commands: init / install / add / remove / update / scripts / run / publish / audit, plus lockfile, registry, and cache management — with common options and practical examples.
34 commands
npm 10+
pnpm
Quick reference for pnpm: install / add / remove / update, scripts, workspaces, store & cache and config — focused on the GitHub-site pnpm repo workflow, with options and practical examples.
31 commands
pnpm 9+
npx
Quick reference for npx commands: run one-off package binaries, scaffold projects, manage the npx cache, pin versions, and avoid pitfalls with interactive CLIs — with common options and practical examples.
25 commands
npx 10+ (shipped with npm)
vite
Quick reference for Vite CLI commands: dev server, build, preview, dependency pre-bundling, plugin management, environment variables, and project inspection — with common options and practical examples.
30 commands
Vite 5+
Trademark & Use Notice
These command-line tool cheatsheets are open community references. The names, logos, and trademarks of the tools referenced here (such as Git™, Docker™, Kubernetes®, kubectl, PostgreSQL®, MySQL®, Redis™, MongoDB®, Linux™, PowerShell™, Vim™, and others) are the property of their respective owners and are used here solely for identification and reference purposes.
All content in these cheatsheets is independently authored as a simplified, self-contained reference. It is not affiliated with, endorsed by, or sourced from any official documentation. Command listings, flag descriptions, and examples are original simplifications; for authoritative information please consult the official documentation of each tool.
Command syntax and option flags may differ across tool versions. The version tags shown reflect stable releases; behavior may differ in other versions. This cheatsheet does not imply any preference or recommendation by the trademark holders.
If a trademark or copyright owner believes that any content on this site infringes their rights, please send an email to [email protected]. Upon receiving valid proof of rights, we will modify or remove the relevant content within a reasonable period.
This website assumes no legal liability for any direct or indirect losses arising from the use of information presented on these pages.
About Yarn
Yarn was released by Facebook (Meta) in October 2016 as a faster, more deterministic alternative to npm, alongside contributions from Google, Exponent, and Tilde. The original 1.x line is now called "Yarn Classic" and is in maintenance mode; the active line is "Yarn Berry" (2.0 in 2020, 3.0 in 2021, 4.0 in 2022, 5.x today). Yarn Berry ships `yarn` (a single 4 MB binary with Node embedded), `yarn dlx` (npx replacement), `yarn workspaces`, and Plug'n'Play (`yarn install --immutable` plus `.pnp.cjs`) — a controversial default that installs no `node_modules` and resolves packages from a single zip store. Berry is configured in a `yarnrc.yml` file (YAML, unlike Classic's `yarnrc` ini). Both lines coexist on the same machine: `yarn set version classic` and `yarn set version berry` switch the binary. Yarn is faster than npm at install (parallel + cache), supports `workspaces` and `constraints` for monorepo policy, and has built-in `yarn why` / `yarn licenses` introspection. No data is sent to Meta — Yarn is independent OSS under BSD-2-Clause.
Cheatsheet version 1.0.0