DEV Community

ryanzzff
ryanzzff

Posted on

Using Cocoapods with Gemfile

If you work in a team, it would be better if all team members have the same development environment. For instance, as an iOS developer, if we are using a different version of Cocoapods to install the 3rd party libraries, the generated Podfile.lock or the .xcworkspace file might be slightly different.

We can use a Gemfile to sync it:

Step 1. Create a file named Gemfile in the same directory of the Podfile and .xcodeproj

source 'https://rubygems.org'
gem 'cocoapods'

you may also specify the version of the cocoapods:

source 'https://rubygems.org'
gem "cocoapods", "1.8.4"

Step 2. Install bundler with gem in user directory

gem install bundler --user-install

Step 3. Install cocoapods with the version specified for the project (into the local relative path vendor/bundle)

bundle install --path vendor/bundle

To verify the version installed:

bundle exec pod --version

Step 4. Instead of using pod install, we now have to use a new command:

bundle exec pod install

Bonus:
We can open the .xcworkspace file automatically with Xcode right after pod install:

bundle exec pod install && xed .

Top comments (0)