Skip to main content

Ruby environment setup with rbenv and bundler

Setup for ruby development environment. We will use rbenv (version manager) + bundler (project environment manager)

Setup rbenv

This section is for the installation of rbenv itself. It should be only done once per machine.

rbenv is a ruby version manager that allows installation, switching, and scoping of multiple ruby versions.

  1. Install rbenv with OS package manager

    Mac OS
    brew install rbenv ruby-build
  2. Check your installation with rbenv init

    rbenv init
  3. Add rbenv to shell init script.

    zsh
    echo '# Ruby' >> ~/.zprofile
    echo 'eval "$(rbenv init - zsh)"' >> ~/.zprofile

    eval "$(rbenv init - zsh) should be whatever is outputted by step 2.

    If you put this in ~/.zprofile, relog.

    If you put this in ~/.zshrc, run source ~/.zshrc.

  4. Install the ruby version you want

    rbenv install -l # Lists all latest stable ruby version available
    rbenv install <RUBY_VERSION> # <RUBY_VERSION> is one of the outputs from previous command.
  5. Set global ruby version

    rbenv global <RUBY_VERSION>
  6. Check ruby installation

    which ruby # Should output ~/.rbenv/shims/ruby instead of /bin/ruby
    ruby --version # Should output previously set global ruby version

Setup project environment

This section is for configuring project environment. It should be done per project.

  1. Install dependencies defined in Gemfile. On the working directory with Gemfile run

    bundle install
  2. Run the ruby file within the current project context

    bundle exec ruby <ruby_file>