Setting up a good Ruby 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
brew if needed.Install
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew install ruby-build
wget if needed.Install
brew install wget
brew install rbenv-default-gems
brew install chruby
Add the following to the
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 2.4.3 (latest patch). In this example, we're using 2.4.3.
# Make ~/.rubies folder if it doesn't exist mkdir ~/.rubies # !!!!!!!!!!! Get list of latest version of ruby !!!!!!!!!!!! ruby-build --definitions # Install latests version of 2.4.3 # If you want other versions feel free to go to town ruby-build 2.4.3 ~/.rubies/2.4.3
To set a default ruby to be used, add the following to the to the
you don't have to include the patch number, the latest will always be used. From now on you can use the command
chruby 2.4.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
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.
For every version of ruby installed, be sure to
gem install bundler. for example:
chruby 2.4.3 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.