# Managing dependencies with CocoaPods

[CocoaPods](https://cocoapods.org/) is a dependency manager for Swift and Objective-C Cocoa projects. An iOS app with CocoaPods dependencies needs to have a `Podfile` with a number of pods listed in it: these pods are installed during the process of building the app.

You can, of course, easily install CocoaPods dependencies during a Bitrise build. You just need our dedicated Step: **[Run CocoaPods Install](https://github.com/bitrise-io/steps-cocoapods-install)**. The Step can run both `pod install` and `pod update` commands.

## Installing CocoaPods dependencies

To install your dependencies with CocoaPods:

**Workflow Editor**

1. If you need a specific version of CocoaPods, make sure you define it either in the `Gemfile.lock` or the `Podfile.lock` file.

   The Step first looks for the `cocoapods` gem in the `Gemfile.lock` file. If there's no `cocoapods` gem there, the Step uses the CocoaPods version defined in the `Podfile.lock` file. If the version is not defined in either file, the preinstalled system version will be used which you can check in the [stack reports](https://stacks.bitrise.io/stack_reports/).
1. Make sure that the Xcode Step building your app uses your `.xcworkspace` file: the **Project path** input of the Step should point to the path of `.xcworkspace`.
1. Add the [**Run CocoaPods Install**](https://github.com/bitrise-io/steps-cocoapods-install) Step to your Workflow.

   It should come after any Step that pulls [from the build cache](/bitrise-build-cache/getting-started-with-the-build-cache/getting-started-with-the-build-cache). If you don't have any caching Steps, add the Step right after the [**Git Clone Repository**](https://github.com/bitrise-steplib/steps-git-clone) Step.
1. In the **CocoaPods command** input, select the command you wish to run.

   **install**: Installs the version specified in the `Podfile` for each pod.

   **update**: Installs the latest version for each pod listed in the `Podfile`.

   ![pod-install.png](/img/_paligo/uuid-92405804-e42c-f788-4026-7339492f1113.png)
1. Optionally, you can specify a path to your `Podfile` in the **Podfile path** input.

   This is not mandatory: if you leave the input empty, the Step performs a recursive search in the root directory of your app, and uses the first `Podfile` it finds.

**Configuration YAML**

1. If you need a specific version of CocoaPods, make sure you define it either in the `Gemfile.lock` or the `Podfile.lock` file.

   The Step first looks for the `cocoapods` gem in the `Gemfile.lock` file. If there's no `cocoapods` gem there, the Step uses the CocoaPods version defined in the `Podfile.lock` file. If the version is not defined in either file, the preinstalled system version will be used which you can check in the [stack reports](https://stacks.bitrise.io/stack_reports/).
1. Make sure that the Xcode Step building your app uses your `.xcworkspace` file: the `project_path` input of the Step should point to the path of `.xcworkspace`.
1. Add the `cocoapods-install` Step to your Workflow.

   It should come after any Step that pulls [from the build cache](/bitrise-build-cache/getting-started-with-the-build-cache/getting-started-with-the-build-cache). If you don't have any caching Steps, add the Step right after the `git-clone` Step.

   ```yml
   my-workflow:
     steps:
       - activate-ssh-key: {}
       - git-clone: {}
       - restore-cocoapods-cache: {}
       - cocoapods-install:
           is_always_run: true
       - save-cocoapods-cache: {}
   ```
1. In the `command` input, select the command you wish to run.

   **install**: Installs the version specified in the `Podfile` for each pod.

   **update**: Installs the latest version for each pod listed in the `Podfile`.

   ```yml
   my-workflow:
     steps:
       - activate-ssh-key: {}
       - git-clone: {}
       - restore-cocoapods-cache: {}
       - cocoapods-install:
           is_always_run: true
           inputs:
             - command: update
       - save-cocoapods-cache: {}
   ```
1. Optionally, you can specify a path to your `Podfile` in the `podfile_path` input.

   ```yml
   my-workflow:
     steps:
       - activate-ssh-key: {}
       - git-clone: {}
       - restore-cocoapods-cache: {}
       - cocoapods-install:
           is_always_run: true
           inputs:
             - command: update
             - podfile_path: ./path/to/podfile/
       - save-cocoapods-cache: {}
   ```

   This is not mandatory: if you leave the input empty, the Step performs a recursive search in the root directory of your app, and uses the first `Podfile` it finds.

## Caching CocoaPods dependencies

With key-based caching, you only need the [**Restore CocoaPods cache**](https://github.com/bitrise-steplib/bitrise-step-restore-cocoapods-cache) and the [**Save CocoaPods cache**](https://github.com/bitrise-steplib/bitrise-step-save-cocoapods-cache) Steps to cache your pods. These Steps require no configuration as they automatically set up the cache keys needed for your dependencies.

1. Add the [**Restore CocoaPods cache**](https://github.com/bitrise-steplib/bitrise-step-restore-cocoapods-cache) Step to your Workflow

   It should come before the [**Run CocoaPods install**](https://github.com/bitrise-io/steps-cocoapods-install) Step or any Step that needs dependencies to build your app, such as [**Xcode Archive & Export for iOS**](https://github.com/bitrise-steplib/steps-xcode-archive).

   ![restore-pods.png](/img/_paligo/uuid-3305dee6-a952-5073-e44b-02fd8c3925c1.png)
1. Add the [**Save CocoaPods cache**](https://github.com/bitrise-steplib/bitrise-step-save-cocoapods-cache) Step to the end of your Workflow.
