> For the complete documentation index, see [llms.txt](https://www.ankitavirani.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.ankitavirani.com/experience/packege-mangers/commands-cheatsheet.md).

# Commands cheatsheet

If you want to get rid off all those different commands on each package manager I higly recommened to install [SWPM](https://www.npmjs.com/package/swpm) and say good bye to package manager confussion. It will do all the commands translation for you.

### Package Commands

<table><thead><tr><th width="142">command</th><th>npm</th><th>yarn</th><th>yarn (berry)</th><th>pnpm</th><th>bun</th></tr></thead><tbody><tr><td>clean cache</td><td><code>npm cache clean</code></td><td><code>yarn cache clean</code></td><td><code>yarn cache clean</code></td><td>N/A</td><td><code>bun pm cache rm</code></td></tr><tr><td>install from <code>package.json</code></td><td><code>npm install</code></td><td><code>yarn [install]</code></td><td><code>yarn [install]</code></td><td><code>pnpm install</code></td><td><code>bun install</code></td></tr><tr><td>don't read or generate a lockfile</td><td><code>npm install --no-package-lock</code></td><td><code>yarn install --no-lockfile</code></td><td><code>yarn install --no-lockfile</code></td><td>N/A</td><td><code>bun install --no-save</code></td></tr><tr><td>don't generate a lockfile</td><td></td><td><code>yarn install --pure-lockfile</code></td><td><code>yarn install --pure-lockfile</code></td><td></td><td>N/A</td></tr><tr><td>lockfile is not updated</td><td><code>npm ci</code></td><td><code>yarn install --frozen-lockfile</code></td><td><code>yarn install --immutable</code></td><td><code>pnpm install --frozen-lockfile</code></td><td><code>bun install --frozen-lockfile</code></td></tr><tr><td>add package</td><td><code>npm install &#x3C;package> [--location=global]</code></td><td><code>yarn [global] add &#x3C;package></code></td><td><code>yarn [global] add &#x3C;package></code></td><td><code>pnpm add &#x3C;package> [--global]</code></td><td><code>bun add &#x3C;package> [--global]</code></td></tr><tr><td>add package as <code>dependencies</code></td><td><code>npm install &#x3C;package></code></td><td><code>yarn add &#x3C;package></code></td><td><code>yarn add &#x3C;package></code></td><td><code>pnpm add &#x3C;package></code></td><td><code>bun add &#x3C;package></code></td></tr><tr><td>add package as <code>devDependencies</code></td><td><code>npm install &#x3C;package> --save-dev</code></td><td><code>yarn add &#x3C;package> --dev</code></td><td><code>yarn add &#x3C;package> --dev</code></td><td><code>pnpm add &#x3C;package> --save-dev</code></td><td><code>bun add &#x3C;package> --dev</code></td></tr><tr><td>add package as <code>optionalDependencies</code></td><td><code>npm install &#x3C;package> --save-optional</code></td><td><code>yarn add &#x3C;package> --optional</code></td><td><code>yarn add &#x3C;package> --optional</code></td><td><code>pnpm add &#x3C;package> --save-optional</code></td><td><code>bun add &#x3C;package> --optional</code></td></tr><tr><td>add package as <code>peerDependencies</code></td><td><code>npm install &#x3C;package> --save-peer</code></td><td><code>yarn add &#x3C;package> --peer</code></td><td><code>yarn add &#x3C;package> --peer</code></td><td><code>pnpm add &#x3C;package> --save-peer</code></td><td>N/A</td></tr><tr><td>add exact version</td><td><code>npm install &#x3C;package> --save-exact</code></td><td><code>yarn add &#x3C;package> --exact</code></td><td><code>yarn add &#x3C;package> --exact</code></td><td><code>pnpm add &#x3C;package> --save-exact</code></td><td><code>bun add &#x3C;package> --exact</code></td></tr><tr><td>remove package</td><td><code>npm uninstall &#x3C;package> [--location=global]</code></td><td><code>yarn [global] remove &#x3C;package></code></td><td><code>yarn [global] remove &#x3C;package></code></td><td><code>pnpm uninstall &#x3C;package> [--global]</code></td><td><code>bun remove [&#x3C;package>] [--global]</code></td></tr><tr><td>remove package as <code>dependencies</code></td><td><code>npm uninstall &#x3C;package></code></td><td><code>yarn remove &#x3C;package></code></td><td><code>yarn remove &#x3C;package></code></td><td><code>pnpm uninstall &#x3C;package></code></td><td><code>bun remove &#x3C;package></code></td></tr><tr><td>remove package as <code>devDependencies</code></td><td><code>npm uninstall &#x3C;package> --save-dev</code></td><td><code>yarn remove &#x3C;package> --dev</code></td><td><code>yarn remove &#x3C;package> --dev</code></td><td><code>pnpm uninstall &#x3C;package> --save-dev</code></td><td><code>bun remove &#x3C;package> --dev</code></td></tr><tr><td>remove package as <code>optionalDependencies</code></td><td><code>npm uninstall &#x3C;package> --save-optional</code></td><td><code>yarn remove &#x3C;package> --optional</code></td><td><code>yarn remove &#x3C;package> --optional</code></td><td><code>pnpm uninstall &#x3C;package> --save-optional</code></td><td><code>bun remove &#x3C;package> --optional</code></td></tr><tr><td>remove package as <code>peerDependencies</code></td><td><code>npm uninstall &#x3C;package> --save-peer</code></td><td><code>yarn remove &#x3C;package> --peer</code></td><td><code>yarn remove &#x3C;package> --peer</code></td><td><code>pnpm uninstall &#x3C;package> --save-peer</code></td><td>N/A</td></tr><tr><td>update package (no <code>package.json</code>)</td><td><code>npm update [&#x3C;package>] [--location=global]</code></td><td><code>yarn [global] upgrade [&#x3C;package>]</code></td><td><code>yarn [global] semver up [&#x3C;package>]</code></td><td><code>pnpm update [&#x3C;package>] [--global]</code></td><td>N/A</td></tr><tr><td>upgrade package on <code>package.json</code></td><td><code>npm install &#x3C;package>@latest [--location=global]</code></td><td><code>yarn [global] upgrade &#x3C;package> --latest</code></td><td><code>yarn [global] up &#x3C;package></code></td><td><code>pnpm update &#x3C;package> --latest [--global]</code></td><td>N/A</td></tr><tr><td>upgrade interactive</td><td>N/A</td><td><code>yarn upgrade-interactive</code></td><td><code>yarn upgrade-interactive</code></td><td><code>pnpm update --interactive</code></td><td>N/A</td></tr><tr><td>list all package at the top level</td><td><code>npm list --depth 0 [--location=global]</code></td><td><code>yarn [global] list --depth 0</code></td><td><code>yarn [global] list --depth 0</code></td><td><code>pnpm list --depth 0 [--global]</code></td><td><code>bun pm ls</code></td></tr><tr><td>audit vulnerable dependencies</td><td><code>npm audit [fix]</code></td><td><code>yarn audit</code></td><td><code>yarn audit</code></td><td><code>pnpm audit [--fix]</code></td><td></td></tr></tbody></table>

### Shared Commands

Use the same command structure between package managers.

| command                            | npm                                            | yarn                                         | yarn (berry)                                    | pnpm                                         | bun                        |
| ---------------------------------- | ---------------------------------------------- | -------------------------------------------- | ----------------------------------------------- | -------------------------------------------- | -------------------------- |
| init or create                     | `npm init`                                     | `yarn init`                                  | `yarn init`                                     | `pnpm init`                                  | `bun init`                 |
| login/logout                       | `npm <login or logout>`                        | `yarn <login or logout>`                     | `yarn <login or logout>`                        | `pnpm <login or logout>`                     | TBA                        |
| run scripts                        | `npm run <script>`                             | `yarn run <script>`                          | `yarn run <script>`                             | `pnpm [run] <script>`                        | `bun run <script>`         |
| run test                           | `npm test`                                     | `yarn test`                                  | `yarn test`                                     | `pnpm test`                                  | `bun test`                 |
| crate bundle package               | `npm build`                                    | `yarn build`                                 | `yarn build`                                    | `pnpm build`                                 | `bun build`                |
| publish                            | `npm publish`                                  | `yarn publish`                               | `yarn npm publish`                              | `pnpm publish`                               | TBA                        |
| unpublish                          | `npm unpublish <package>[@#.#.#]`              | `yarn unpublish <package>[@#.#.#]`           | `yarn unpublish <package>[@#.#.#]`              | `pnpm unpublish <package>[@#.#.#]`           | TBA                        |
| deprecate                          | `npm deprecate <package>[@#.#.#] <message>`    | `yarn deprecate <package>[@#.#.#] <message>` | `yarn deprecate <package>[@#.#.#] <message>`    | `pnpm deprecate <package>[@#.#.#] <message>` | TBA                        |
| config list                        | `npm config list`                              | `yarn config list`                           | `yarn config list`                              | `pnpm config list`                           | TBA                        |
| config `--save-default` as default | `npm config set save-exact true`               | `yarn config set save-exact true`            | `yarn config set save-exact true`               | `pnpm config set save-exact true`            | TBA                        |
| config `~` as default instead `^`  | `npm config set save-prefix '~'`               | `yarn config set save-prefix '~'`            | `yarn config set save-prefix '~'`               | `pnpm config set save-prefix '~'`            | TBA                        |
| list outdated packages             | `npm outdated [<package>] [--location=global]` | `yarn [global] [<package>] outdated`         | `yarn [global] [<package>] upgrade-interactive` | `pnpm outdated [<package>] [--global]`       | TBA                        |
| link local package                 | `npm link [<folder>]`                          | `yarn link [<folder>]`                       | `yarn link [<folder>]`                          | `pnpm link [<folder>]`                       | `bun link [<folder>]`      |
| unlink local package               | \`npm unlink \[\<folder\\                      | package> --no-save]\`                        | \`yarn unlink \[\<folder\\                      | package>]\`                                  | \`yarn unlink \[\<folder\\ |

### Run Remotely

Run a command without installing it.

| command     | npm                      | yarn                 | yarn (berry)         | pnpm                 | bun              |
| ----------- | ------------------------ | -------------------- | -------------------- | -------------------- | ---------------- |
| run package | {% raw %}`npx <package>` | `yarn dlx <package>` | `yarn dlx <package>` | `pnpm dlx <package>` | `bunx <package>` |

### CLI documentation

* [npm](https://docs.npmjs.com/cli/v8/commands)
* [yarn](https://classic.yarnpkg.com/en/docs/cli/)
* [pnpm](https://pnpm.io/cli/install)
* [bun](https://github.com/oven-sh/bun#using-bun-as-a-package-manager)
