Let’s say you use .ruby-version
in your project to ensure that team members use the same version of Ruby.
This is a common approach if you use tools that depend on Ruby, such as Bundler or Cocoapods.
But is the version of Ruby you want to use installed on the Bitrise stack?
If the version of Ruby specified in .ruby-version
is installed on the Bitrise stack, I would say, “No worries at all!”.
You can check the versions of Ruby installed on each stack here.
However, if your stack doesn’t install that version of Ruby, you will encounter errors when running Cocoapods or Bundler. You want to avoid leaving this error alone as part of the CI service experience, right?
I faced the same issue, so I wrote a script to solve this problem. This script installs the specified version of Ruby if it has not already been installed.
Add the following script to the Bitrise Script Step:
#!/usr/bin/env bash
RUBY_VER=$(cat .ruby-version)
if rbenv install --list-all | grep -xq ${RUBY_VER}; then
rbenv install -s
else
set -ex
asdf install ruby $RUBY_VER
asdf global ruby $RUBY_VER
fi
This method will solve the problem, but keep in mind that it takes about 2-3 minutes to install Ruby.
Thank you!