Skip to content

Instantly share code, notes, and snippets.

@andrewroycarter
Last active August 17, 2023 10:44
Show Gist options
  • Save andrewroycarter/6815905 to your computer and use it in GitHub Desktop.
Save andrewroycarter/6815905 to your computer and use it in GitHub Desktop.
Directions on installing chruby, ruby, ruby-build, and bundler.

Setting up a good cocoapods environment

Before you start

Make sure that you have the latest version of Xcode installed from the Mac App Store, and that you have the command line tools installed. To install the command line tools, open Xcode, click Xcode->Preferences->Downloads->Command Line Tools

Install brew if needed.

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Install ruby-build.

brew install ruby-build

Install wget if needed.

brew install wget

Install chruby.

brew install chruby

Add the following to the ~/.bashrc or ~/.zshrc or ~/.bash_profile file:

source /usr/local/opt/chruby/share/chruby/chruby.sh
source /usr/local/opt/chruby/share/chruby/auto.sh

Install desired rubies.

At this time, I'd recommend 1.9.3 (latest patch) and 2.0.0 (latest patch). In this example, we're using 1.9.3-p448 and 2.0.0-p247.

# Make ~/.rubies folder if it doesn't exist
mkdir ~/.rubies
# Get list of latest version of ruby
ruby-build --definitions
# Install latests versions of 1.9.3 and 2.0.0
# If you want other versions feel free to go to town
ruby-build 1.9.3-p448 ~/.rubies/1.9.3-p448
ruby-build 2.0.0-p247 ~/.rubies/2.0.0-p247

To set a default ruby to be used, add the following to the to the ~/.bashrc or ~/.zshrc or ~/.bash_profile.

chruby 1.9.3

you don't have to include the patch number, the latest will always be used. From now on you can use the command chruby 1.9.3 (or whichever version) to change the version of ruby used. If a directory has a .ruby-version file in it, the version of ruby in that file will be used. Example contents of a .ruby-version file would be 1.9.3.

After completing these steps, make sure to source ~/.bash_profile or source ~/.bashrc or source ~/.zshrc so the changes will be applied to your current terminal session.

Install bundler.

For every version of ruby installed, be sure to gem install bundler. for example:

chruby 1.9.3
gem install bundler
chruby 2.0.0
gem install bundler

Bundler is used during the build process to install the correct version of cocoapods specified in the Gemfile in the project directory.

@justanton
Copy link

hi! do you know if it is possible to update Ruby version by using chruby?

@mallyvai
Copy link

@justanton All chruby does is change rubies (hence chruby). It will alert you if the ruby version is out of date, but you'll need to explicitly install the ruby version yourself. Take a look at ruby-install if you want a utility that focuses on installing rubies in a clean way!

@phaseOne
Copy link

phaseOne commented Dec 2, 2021

As of ruby 2.6.0, it's no longer necessary to install bundler separately, as it's part of the default gems.

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