Home/Guides/How to install CocoaPods on a remote Mac and get pod install working

How to install CocoaPods on a remote Mac and get pod install working

Updated · airankrush

What this guide covers

When you finish, pod install runs to completion in your project directory and generates the workspace. You need: Xcode or the Command Line Tools installed, Homebrew (recommended), and network access to the dependency sources.

Steps

  1. Pick an install method that does not need system-level privileges

    The default command on the official CocoaPods getting started page installs with RubyGems. The page notes that with the Ruby that ships with macOS, this command has to run as the superuser. On a rented machine we suggest avoiding that form and using one of the three below.

    Homebrew has a package of the same name, which is the least effort:

    brew install cocoapods
  2. Alternative: install into your own user directory

    The section of the official page on installing without elevated privileges gives two approaches. One is to add --user-install:

    gem install cocoapods --user-install

    Afterwards pod is not necessarily on your PATH; the official example uses gem which cocoapods to find where it went. The other is to set GEM_HOME to a user directory in your shell configuration and add it to PATH. This is the one the official page recommends more; see that page for the exact two lines.

  3. Team projects: lock the version with Bundler

    If the repository has a Gemfile, the project pins the CocoaPods version with Bundler. In that case install with bundle install and run with bundle exec pod install, rather than installing whatever version globally. Mismatched versions produce meaningless changes in Podfile.lock.

  4. The first pod install

    Run this in the directory that contains the Podfile:

    pod install

    When it finishes, open the generated .xcworkspace, not the original .xcodeproj. If it says a version of a dependency cannot be found, add --repo-update so it updates the dependency index before installing. Commit Podfile.lock to the repository.

    The first run downloads every dependency, and speed depends on the line. You can run it inside a tmux session so it keeps going if the remote session disconnects.

  5. Credentials for private dependencies

    When the Podfile references private Git repositories, this machine needs permission to fetch them. We suggest generating a read-only deploy key or access token just for this machine instead of copying your personal full-permission key onto it. That way, before the rental ends you only revoke this one credential on your code hosting platform, and your other devices are unaffected.

  6. Cache and cleanup

    CocoaPods caches the dependencies it has downloaded, and after enough branch and project switches that takes a fair amount of disk:

    pod cache list
    pod cache clean --all

    The Pods directory in the project can be deleted at any time and rebuilt with pod install. pod deintegrate removes CocoaPods from the project altogether; it is not for clearing the cache, so do not use it by mistake.

  7. Keep an eye on the official read-only plan

    The CocoaPods team announced on its official blog that the main repository (trunk) will become read-only, after which it accepts no new pods and no new versions. Existing builds keep working and private sources are unaffected. Go by the announcement for the exact dates.

    This means dependencies will no longer receive updates through trunk. For new projects, consider Swift Package Manager first. Older projects still install as usual, but it is worth starting to take stock of which dependencies have a SwiftPM version.

FAQ

Running pod says "command not found". What now?

If you installed with --user-install, the executable is under the user gem directory and that directory needs to be added to PATH. Installing with Homebrew does not have this problem.

The install fails with no write permission. How do I fix it?

That comes from installing into the system Ruby directory. Do not change permissions on system directories for it; switch to Homebrew or a user-directory install.

pod install is very slow or fails partway. What should I check?

Add --verbose first to see which dependency it is stuck on. Download speed depends on the line and the load. Do not install a proxy or change this machine's network configuration to speed it up; that is outside what is permitted.

What CocoaPods-related cleanup is needed before the rental ends?

The Pods directory and the cache can both be rebuilt, so no backup is needed. What you should do is confirm Podfile and Podfile.lock are committed and pushed, and revoke the private repository credentials you issued for this machine.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All guides