The documentation suggested way of setting this up is terrible - it has no versioning, and it takes a lot of time to install through brew.
The best way is having a Gemfile
that declares the dependencies at the root of your repo, ie:
source 'https://rubygems.org'
gem 'cocoapods'
gem 'fastlane'
Then bundle install
it to lock the versions of the tools on a Gemfile.lock
(you should version both files in your repo).
On your ci_scripts/ci_post_clone.sh
file:
#!/bin/sh
#1 - You can't install gems to the system gem path without sudo, so create a local one
echo ">>> SETUP LOCAL GEM PATH"
echo 'export GEM_HOME=$HOME/gems' >>~/.bash_profile
echo 'export PATH=$HOME/gems/bin:$PATH' >>~/.bash_profile
export GEM_HOME=$HOME/gems
export PATH="$GEM_HOME/bin:$PATH"
#2 - Install the actual bundler version you bundled locally with, so you don't have any surprises
echo ">>> INSTALL REQUIRED BUNDLER VERSION"
gem install bundler -v "$(grep -A 1 "BUNDLED WITH" ../Gemfile.lock | tail -n 1)" --install-dir $GEM_HOME
#3 - Let bundler download the locked version of cocoapods, fastlane, and whatever other tools you need
echo ">>> INSTALL DEPENDENCIES"
bundle install
#4 - Finally you can run the bundled pod binary to install your dependencies
echo ">>> INSTALL PODS"
bundle exec pod install
Also, consider commiting your Pods
folder to avoid the need to run cocoapods at all. Or at least gitignore only large binaries (i.e Twilio, WebRTC, etc). This also protects you from deleted repos or offline services providers