Skip to content

Instantly share code, notes, and snippets.

@colinsurprenant
Last active August 29, 2015 14:11
Show Gist options
  • Save colinsurprenant/f03cc4d0607ddceb81a1 to your computer and use it in GitHub Desktop.
Save colinsurprenant/f03cc4d0607ddceb81a1 to your computer and use it in GitHub Desktop.
rbenv setup

Ruby development environment setup

Yet another step-by-step guide to setting up a Ruby developement environment. Setting up a proper Ruby development environment involves setting up a Ruby Version Manager and Gem dependencies isolation.

rbenv setup

You should never rely on your system installed Ruby but use a Ruby Version Manager. There are 2 main tools for this, RVM and rbenv. This is a guide for rbenv which I prefer for its simple, minimalist, less intrusive approach and its rich plugins ecosystem.

installation

Make sure you are logged in as a normal user not as root, rbenv will be installed in $HOME/.rbenv.

install rbenv

mkdir ~/.rbenv/plugins

install ruby-build plugin

This plugin will enable the rbenv build ... command to easily build any Ruby version.

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

install rbenv-update plugin

This plugin will enable the rbenv update command to easily update code and list of buildable rubies.

git clone https://github.com/rkh/rbenv-update.git ~/.rbenv/plugins/rbenv-update

install rbenv-gem-rehash plugin

This plugin will automate the rbenv rehash command after gem installation.

git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

optionally install rbenv-aliases plugin

This plugin allow using shorter names for Ruby versions. See rbenv-aliases repo for usage.

git clone git://github.com/tpope/rbenv-aliases.git ~/.rbenv/plugins/rbenv-aliases

install your ruby versions

  • first update list of available rubies (which will incidentally also update all rbenv related code).
rbenv update
  • view list of available rubies for installation
rbenv install --list
  • install rubies, for example:
rbenv install jruby-1.7.17
rbenv rehash
rbenv install 1.9.3-p551
rbenv rehash
rbenv install 2.1.5
rbenv rehash

usage

  • create a root directory for your project and go to it
  • tell rbenv which Ruby to use when in this directory and below
rbenv local jruby-1.7.17
  • verify
ruby -v
jruby 1.7.17 (1.9.3p392) 2014-12-09 fafd1a7 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_11-b21 +jit [darwin-x86_64]
  • the first time you use a new Ruby, make sure the bundler gem is installed
gem install bundler --no-ri --no-rdoc

some useful commands

  • list all installed rubies
rbenv versions
  • similar to rbenv local

    • set the global version of Ruby to be used in all shells
    rbenv global 1.9.3-p551
    • sets a shell-specific Ruby version by setting the RBENV_VERSION environment variable in your shell
    rbenv shell 1.9.3-p551

Bundler setup

To manage the gem dependencies of your project you will be using Bundler by typically creating a Gemfile in the root of your project.

Bundler default options

I suggest you use the following default options for Bundler by creating the ~/.bundler/config file with:

---
BUNDLE_PATH: vendor
BUNDLE_DISABLE_SHARED_GEMS: '1'

This will make sure your project isolate its dependencies by installing all gems into the vendor/ directory and do not use any system provided gems.

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