import { Callout } from "../../../../components/Callout";
import HeartIcon from "@heroicons/react/solid/HeartIcon";
import { Tabs, Tab } from "../../../../components/Tabs";

# Package Installation

A package manager (like `npm`) handles two things for you: [managing workspaces](/repo/docs/handbook/workspaces) and installing packages.

Turborepo is compatible with four package managers:

- [npm](https://docs.npmjs.com/cli/v8/using-npm/workspaces/#description)
- [pnpm](https://pnpm.io/workspaces)
- [Yarn 1](https://classic.yarnpkg.com/lang/en/docs/workspaces/)
- Yarn >=2 (docs coming soon)

You should use whichever you feel most comfortable with - but **if you're a monorepo beginner, we recommend npm**.

If you're **comfortable with monorepos, we recommend pnpm**. It's faster and offers some useful CLI options like `--filter`.

## Installing packages

When you first clone or create your monorepo, you'll need to:

1. Make sure you're in the root directory of your monorepo
2. Run the install command:

<Tabs items={["npm", "yarn", "pnpm"]} storageKey="selected-pkg-manager">
  <Tab>

    ```bash
    npm install
    ```

  </Tab>
  <Tab>

    ```bash
    yarn install
    ```

  </Tab>
  <Tab>

    ```bash
    pnpm install
    ```

  </Tab>
</Tabs>

You'll now see `node_modules` folders appear in the root of your repository, and in each workspace.

## Adding/removing/upgrading packages

You can add, remove and upgrade packages from within your monorepo using your package manager's built-in commands:

<Tabs items={['npm', 'yarn', 'pnpm']} storageKey="selected-pkg-manager">
  <Tab>

    **Install a package in a workspace**
    ```bash
    npm install <package> --workspace=<workspace>
    ```

    Example:
    ```bash
    npm install react --workspace=web
    ```

    **Remove a package from a workspace**
    ```bash
    npm uninstall <package> --workspace=<workspace>
    ```

    Example:
    ```bash
    npm uninstall react --workspace=web
    ```

    **Upgrade a package in a workspace**
    ```bash
    npm update <package> --workspace=<workspace>
    ```

    Example:
    ```bash
    npm update react --workspace=web
    ```

  </Tab>
  <Tab>

    **Install a package in a workspace**
    ```bash
    yarn workspace <workspace> add <package>
    ```

    Example:
    ```bash
    yarn workspace web add react
    ```

    **Remove a package from a workspace**
    ```bash
    yarn workspace <workspace> remove <package>
    ```

    Example:
    ```bash
    yarn workspace web remove react
    ```

    **Upgrade a package in a workspace**
    ```bash
    yarn workspace <workspace> upgrade <package>
    ```

    Example:
    ```bash
    yarn workspace web upgrade react
    ```

  </Tab>
  <Tab>

    **Install a package in a workspace**
    ```bash
    pnpm add <package> --filter <workspace>
    ```

    Example:
    ```bash
    pnpm add react --filter web
    ```

    **Remove a package from a workspace**
     ```bash
    pnpm uninstall <package> --filter <workspace>
    ```

    Example:
    ```bash
    pnpm uninstall react --filter web
    ```

    **Upgrade a package in a workspace**
     ```bash
    pnpm update <package> --filter <workspace>
    ```

    Example:
    ```bash
    pnpm update react --filter web
    ```

  </Tab>
</Tabs>
