Fix: cmake: command not found Error in CocoaPods on macOS

Fix: cmake: command not found Error in CocoaPods on macOS

Written by

in

Quick answer: The error occurs because a CocoaPods dependency requires CMake to build native code, but CMake isn’t installed on your Mac. Fix it by installing CMake via Homebrew: run brew install cmake in Terminal, then retry pod install.

Why this happens

When you add a pod that includes native C or C++ code (like the Matomo/PiwikTracker SDK in the example), CocoaPods attempts to compile that code during pod install. The pod’s build script invokes cmake to generate an Xcode project for the native portion. If CMake isn’t installed on your Mac, the shell returns /bin/bash: line 4: cmake: command not found and the pod installation fails.

This is common with pods that vendor libraries written in C/C++ (analytics SDKs, image processing, cryptography, etc.). CocoaPods itself doesn’t bundle CMake; it expects the developer’s machine to have it available in PATH.

How to fix it

1. Install Homebrew (if missing)

Homebrew is the standard package manager for macOS command-line tools. If you don’t have it yet, install it first:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Follow the on-screen instructions to add Homebrew to your PATH (usually /opt/homebrew/bin on Apple Silicon, /usr/local/bin on Intel).

2. Install CMake via Homebrew

Once Homebrew is ready, install CMake:

brew install cmake

Verify the installation:

cmake --version
# Example output: cmake version 3.28.3

3. Re-run pod install

Go back to your project directory and run:

pod install

The pod’s build script should now find cmake and complete successfully.

Alternative: Install CMake without Homebrew

If you cannot use Homebrew, download the macOS universal binary from the official CMake releases page, open the .dmg, and run the “Install for command line use” script, or copy the cmake binary to a directory in your PATH (e.g., /usr/local/bin).

How to prevent it

  • Keep Homebrew and its packages updated: brew update && brew upgrade cmake periodically.
  • Document CMake as a project prerequisite in your README or onboarding docs so new team members install it before their first pod install.
  • Consider adding a brew bundle Brewfile to your repo with brew "cmake" so dependencies are declarative.
  • Use Xcode’s Run Script build phases sparingly; prefer CocoaPods’ native prepare_command or vendored_frameworks when possible to avoid custom shell invocations.

FAQ

Does this error mean my Xcode installation is broken?

No. Xcode includes its own CMake for internal use, but it doesn’t expose the cmake binary in the system PATH for CocoaPods scripts. Installing CMake via Homebrew is the standard workaround.

Can I use MacPorts instead of Homebrew?

Yes. Run sudo port install cmake if you prefer MacPorts. The result is the same: a cmake binary in your PATH.

Why does the error mention a specific pod cache path?

CocoaPods downloads and builds each pod in ~/Library/Caches/CocoaPods/Pods/Release/<pod-name>/<version>/. The build script runs inside that directory, so the error shows the exact working directory where cmake was invoked and failed.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.