CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. With over 60 thousand libraries, it is the most popular repository of its kind, impacting over 3 million apps (quoting the official site).
Traditionally, the CocoaPods only targeted macOS, which made sense as it was meant to work with Xcode and the related toolchain. However, the success of cross-platform development frameworks such as Flutter or React Native gave rise to demand for CocoaPods to work on non-macOS platforms such as Windows (for example, some folks have reported issues #8055 and #8077).
Starting with CocoaPods 1.7 (in Beta as of time of writing), it is now possible to get some basic operations, such as pod install and pod update to run on Windows. This guide walks through the necessary steps to get this to work.
Step one — install Ruby
Ruby is required to run CocoaPods. An easy way to install Ruby is to download an installer from https://rubyinstaller.org/. Use the recommended download (Ruby+DevKit x64) unless you have a reason to install a different package.
When installing Ruby, accept the defaults but make sure “Use UTF-8 as default external encoding” is selected. Ruby will prompt to install MSYS — pick the first option (MSYS2 base installation).
To confirm that Ruby has been properly installed, open a command prompt and type “gem list”. If a list of gems is displayed, you’re all set.
Step two — install curl
CocoaPods uses curl to download packages. Since curl is not installed by default on Windows machines, you will need to install it — you can get curl from https://curl.haxx.se/dlwiz/?type=bin&os=Win64&flav=-&ver=*&cpu=x86_64. Download the latest 64-bit curl, extract the package and make sure that curl.exe in accessible via command line.
For example, if you’ve extracted curl as C:\curl-7.64.1_1-win64-mingw, add the following to your path: C:\curl-7.64.1_1-win64-mingw\bin (see “Environment Variables” in Advanced System Settings).
To confirm that curl has been installed, open a command prompt and type “curl — help” — this should display the curl help pages.
Step three — install git
CocoaPods needs git and tar command-line tools. You can install git from https://git-scm.com/download/win. When installing git, you may select the “Use Git and optional Unix tools from the Command Prompt”. Use default settings for everything else.
To confirm that git and Unix tools have been installed, open a command prompt and type the “git” and “tar” commands.
Step four — install CocoaPods
Now that all the tools have been installed, install CocoaPods.
Run “gem install cocoapods” to install the latest released version of CocoaPods. At the time of the writing, Windows support is only available in the Beta of CocoaPods 1.7.0, meaning you will need to run “gem install cocoapods — pre” instead.
To confirm, open a command prompt and run the following command: “pod — version”. You should see version 1.7.0 or higher.
Step five — running pod commands (optional)
In order to run “pod install”, you need an actual Xcode project. Since Xcode does not run on Windows, use a macOS machine with Xcode to generate an Xcode project. To test CocoaPods:
- Transfer the Xcode project to the Windows machine
- Navigate to the project folder using the command line
- Run “pod init” to create the Podfile
- Edit the Podfile and add some pods (for example, you can add “Firebase/Analytics”)
- Run “pod install” to install the pods