Skip to content

Instantly share code, notes, and snippets.

@konradzdunczyk
Last active May 24, 2024 17:54
Show Gist options
  • Save konradzdunczyk/3c07012b68cf4cf2185945242e544a21 to your computer and use it in GitHub Desktop.
Save konradzdunczyk/3c07012b68cf4cf2185945242e544a21 to your computer and use it in GitHub Desktop.
How to install cocapods like a champ (or other ruby-based tools)

How to install cocapods like a champ (or other ruby-based tools)

I want to share with you how I manage my toolset as iOS developer. iOS development is based on 3rd party tools (like cocapods, fastlane) and those tools are, mostly, writen in ruby. So we need to take care of ruby environment if we want to our work be no problematic and efficiant.

First of all - default macOS ruby is shit. Just accept that. We need to replace it and the best way to do it is a tool like rbenv. Rbenv is not only tool for this job, but it's good to start.

Second - brew is an excellent tool but not everything need to be installed via it. I know, it's tempting to use only one package manager for everything but life is life and it's not perfect.

So if you have issues like this:

  1. you installed cocoapods via homebrew and have a problem
  2. you need use sudo when you call gem / bundle / pod / fastlane

then that text is for you.

In the text I use "cocoapods" as example of ruby-based tool but you can replaced it with fastlane or others.

What we want to achive?

  1. Replace default ruby
  2. Stop using brew to install ruby-based tools
  3. Stop using sudo to install / run your tools/packages
  4. Start using gem / bundler to install ruby-based tools

I alredy have cocoapods

If you have installed cocoapods via homebrew or default ruby/gem then it's a good time to get rid of it. Calm down, it's for your good. Trust me.

Let's do it

Almos everything we are going to do in terminal. TIP: If in some point you get prompt "Unknown command", "Command not found" or similar then just restart terminal or open new terminal's tab. Sometimes terminal's session need to be refreshed.

  1. Install Xcode - Xcode contains git and other tools which are needed

  2. Install homebrew. Yes, homebrew is a great tool to install other tools which will install tools of our need. Welcome in iOS Dev world.
    https://brew.sh/

  3. Install rbenv via homebrew. Be strict to instruction on rbenv's github
    https://github.com/rbenv/rbenv#using-package-managers

  4. Install ruby via rbenv (version 3.1.2 will be fine)
    https://github.com/rbenv/rbenv#installing-ruby-versions

  5. Set installed ruby as global
    https://github.com/rbenv/rbenv#rbenv-global

  6. Check if everything is set corectly. It's very important step. We don't want to use system ruby
    ruby -v
    You should get the same version which you installed in step 3.

  7. Install bundler - I realy recomand to use bundler if you work in a team. Unified versions od tools across the team is a half of success.'
    gem install bundler - note the R at the end. Package to install has R at the end, but command doesn't.

  8. Go to your ios project repo (in terminal of cource)

  9. Create Gemfile
    bundle init - No R at the end

  10. Add cocoapods and other packages to Gemfile
    bundle add cocoapods

  11. Install packages. Gemfile.lock file will be created. Both, Gemfile and Gemfile.lock, should be commited to repo.
    bundle install

  12. Use cocoapods like a champ. You can have many versions of cocoapods in your system but bundler help you (bundle exec) to run proper one (defined in your Gemfile.lock)
    bundle exec pod install

BUTs:

  1. "I like my way more and I don't have any problem"
    Just ignore this text. I have worked out this method through years of practice and works for me. I feel that I have control what tools I use

  2. "I don't like bundler \ I work alone \ I want to have one version of cocoapods globally"
    Just use gem install cocoapods in step 7 and use cocoapods like before. Replace of default ruby is your main goal.

  3. "Your english is shit"
    I know but I'm trying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment