Yarn Cheat Sheet: Classic & Berry Commands
Yarn commands for Classic and Berry, side by side, in one reference.
Install, run, and manage workspaces with Yarn.
Core commands
| Command | Does |
|---|---|
| yarn install | Install dependencies |
| yarn install --immutable | CI install (Berry), no lockfile change |
| yarn add pkg | Add a dependency |
| yarn add -D pkg | Add devDependency |
| yarn remove pkg | Remove a dependency |
| yarn <script> | Run a script directly |
| yarn dlx pkg | Run binary without install (Berry) |
Workspaces
| Command | Does |
|---|---|
| yarn workspaces list | List workspaces (Berry) |
| yarn workspace app add pkg | Add dep to one workspace |
| yarn workspaces foreach run build | Run across workspaces (Berry) |
Classic vs Berry
| Concern | Note |
|---|---|
| CI install | Classic: --frozen-lockfile / Berry: --immutable |
| Run scripts | yarn run name or just yarn name |
| PnP | Berry default; .yarn/cache replaces node_modules |
Key takeaways
- Berry uses --immutable; Classic uses --frozen-lockfile for CI.
- yarn <script> runs a script without the explicit run keyword.
- Berry Plug n Play removes node_modules in favor of .yarn/cache.
Related guides
npm Scripts Cheat Sheet: Commands, Lifecycle & CI FlagsAn npm scripts cheat sheet - run, ci, install, lifecycle hooks, pre/post scripts, and the npm flags you use i…
pnpm Cheat Sheet: Install, Workspaces & FiltersA pnpm cheat sheet - install, add, run, frozen-lockfile, workspace filters, and the store commands that make…
Semantic Versioning Cheat Sheet: SemVer Rules & RangesA semantic versioning cheat sheet - MAJOR.MINOR.PATCH rules, prerelease and build metadata, and the npm range…