Manage ruby installion and environment for a non-fuss and non-headache development on multiple supported Ruby versions.
RBENV - https://github.com/rbenv/rbenv
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.
RUBY-BUILD - https://github.com/rbenv/ruby-build
Install any ruby version from source that works well with Rbenv
- Install from command-line (ie can be scripted).
- Install any version available easily
BUNDLER - http://bundler.io/
Most popular way to manage your projects Gems.
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
# 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
cd ~/.rbenv
git pull
cd "$(rbenv root)"/plugins/ruby-build
git pull