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:
- you installed cocoapods via homebrew and have a problem
- 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.
- Replace default ruby
- Stop using brew to install ruby-based tools
- Stop using sudo to install / run your tools/packages
- Start using gem / bundler to install ruby-based tools
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.
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.
-
Install Xcode - Xcode contains git and other tools which are needed
-
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/ -
Install rbenv via homebrew. Be strict to instruction on rbenv's github
https://github.com/rbenv/rbenv#using-package-managers -
Install ruby via rbenv (version 3.1.2 will be fine)
https://github.com/rbenv/rbenv#installing-ruby-versions -
Set installed ruby as global
https://github.com/rbenv/rbenv#rbenv-global -
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. -
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. -
Go to your ios project repo (in terminal of cource)
-
Create Gemfile
bundle init
- No R at the end -
Add cocoapods and other packages to Gemfile
bundle add cocoapods
-
Install packages. Gemfile.lock file will be created. Both, Gemfile and Gemfile.lock, should be commited to repo.
bundle install
-
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
-
"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 -
"I don't like bundler \ I work alone \ I want to have one version of cocoapods globally"
Just usegem install cocoapods
in step 7 and use cocoapods like before. Replace of default ruby is your main goal.