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.
Install rbenv with OS package manager
Mac OSbrew install rbenv ruby-build
Check your installation with
rbenv init
rbenv init
Add rbenv to shell init script.
zshecho '# Ruby' >> ~/.zprofile
echo 'eval "$(rbenv init - zsh)"' >> ~/.zprofileeval "$(rbenv init - zsh)
should be whatever is outputted by step 2.If you put this in
~/.zprofile
, relog.If you put this in
~/.zshrc
, runsource ~/.zshrc
.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.Set global ruby version
rbenv global <RUBY_VERSION>
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.
Install dependencies defined in
Gemfile
. On the working directory withGemfile
runbundle install
Run the ruby file within the current project context
bundle exec ruby <ruby_file>