Skip to content

Instantly share code, notes, and snippets.

@jonyeezs
Last active February 19, 2023 05:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonyeezs/0cd34840004ca2052ff74378e15b39c0 to your computer and use it in GitHub Desktop.
Save jonyeezs/0cd34840004ca2052ff74378e15b39c0 to your computer and use it in GitHub Desktop.
Recommended Ruby Dev Setup

rbenv & Ruby-build + Bundler

Manage ruby installion and environment for a non-fuss and non-headache development on multiple supported Ruby versions.

Manage your Ruby version for your application and global environment.

  • Uses environment variable to maintain so it's easily configurable.
  • Application specific versioning.
  • Doesn't need to be configured in your shell.
  • Works with Ruby versioned Bundler.

Install any ruby version from source that works well with Rbenv

  • Install from command-line (ie can be scripted).
  • Install any version available easily

Most popular way to manage your projects Gems.

Installation

Script provided works with zsh. If you're using a different shell, replace anywhere that mentions .zshrc with your shell's config file.

# Pre-requisites to install
apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install rbenv and ruby-build
brew install rbenv ruby-build
~/.rbenv/bin/rbenv init

# Following instruction is usually given from the step above; if not may need to consult the output of above
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
# Reload shell
. ~/.zshrc

# Install latest ruby and this gives us Rubygems
rbenv install 2.5.0
rbenv rehash
rbenv global 2.5.0

# Install bundler
gem install bundler

## Install rbenv-bundler to make rbenv bundler aware
git clone -- https://github.com/carsomyr/rbenv-bundler.git \
  ~/.rbenv/plugins/bundler

Usage

# Install a new Ruby version
rbenv install --list
rbenv install 2.3.0

# Run the command below after you install a new version of Ruby, or install a gem that provides commands.
rbenv rehash

# Lists all Ruby versions known to rbenv, and shows an asterisk next to the currently active version.
$ rbenv versions

# Bundle with the correct project's correct version
cd to-ruby-project-with-Gemfile
# Suppose the project uses Ruby version `2.3.0`.
rbenv local 2.3.0
bundle install

# If `rake` is a Bundler-installed gem executable, report its location
# with `rbenv which`. The result should look like
# `${RBENV_ROOT}/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rake-10.3.2
# /bin/rake` instead of `${RBENV_ROOT}/versions/2.1.4/bin/rake`.
rbenv which rake

# Run `rake` without having to type `bundle exec rake`.
rake

Upgrading

rbenv

cd ~/.rbenv
git pull

ruby-build

cd "$(rbenv root)"/plugins/ruby-build
git pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment