As an iOS mobile developer, you may think you don’t need to manage Ruby versions in your project. Many iOS projects use CocoaPods which is a Ruby gem. Some projects may even use other Ruby gems such as fastlane for automating your deployment pipeline, or slather for reporting code coverage results. Here at Metova, we use bundler to manage our gem versions, but it’s also important to manage your Ruby version as well. Sometimes some of the gems used for your project may have known bugs with specific Ruby versions that haven’t been fixed yet or they only support specific Ruby versions. When you manage your Ruby version, you can take more control over your environment. By doing this, you’ll know that if everything works on your machine, it will work on other machines too. Specifically:

  1.  Other developers working on your project won’t have to waste time trying to set up their environment to work for the project.
  2. You don’t have to worry about changing your Ruby version if you’re switching back and forth between different projects that require different Ruby versions.
  3. You’ll avoid Ruby version issues with your continuous integration server.

 

What is rbenv?

rbenv is a lightweight Ruby version management tool that makes it easy to control your Ruby environment. It’s an alternative to RVM. Using rbenv, it is easy to install a new version of Ruby and specify which version your project will use. The more things you can control, the fewer random errors you will get.

 

How to Use rbenv for Ruby Version Management

Below are the steps you can take to get your iOS project set up to use a managed version of Ruby using rbenv.

  1. Install rbenv by following the steps on GitHub.
  2. Create a file named “.ruby-version” in the project’s root directory:
    touch .ruby-version
  3. Set the contents of the .ruby-version file to be the ruby version you want to use (e.g. 2.3.0):
    echo '2.3.0' >> .ruby-version
    You can view a list of all the Ruby versions rbenv knows about by running the following command:
    rbenv install -l
  4. Install the Ruby version you need:
    rbenv install 2.3.0
  5. Install the gems you need for that version of Ruby:
    gem install bundler
    bundle install