Latest Ruby Setup for development

Each Linux distribution has its version of Ruby. But they tends to be much older than current Ruby releases.


You can set up latest version with rbenv.
Get rbenv as a distribution package or rbenv-installer is available for the latest rbenv.

curl -fsSL | bash

rbenv-installer clones rbenv repo under $HOME/.rbenv/.
Then ~/.rbenv/bin/rbenv init shows a snippet for .bashrc.

rbenv other than home dir

rbenv can be setup in any directory other than ~/.rbenv.
Add RBENV_ROOT before rbenv init in .bashrc.

export RBENV_ROOT=/other/dir/.rbenv/
eval "$(/other/dir/.rbenv/bin/rbenv init - bash)"

Install ruby version

rbenv install --list shows available Ruby versions. You can install each version with like rbenv install 3.2.0.

Each Ruby version will be installed under $HOME/.rbenv/versions/.
Symlink with ln -s can change actual install path. It can be useful for utilizing persistent storage on container environments.

rbenv install will compile Ruby sources, so several dev packages like zlib1g-dev and libyaml-dev are needed.

After install, rbenv global 3.2.0 can switch the active version.
As official How it works describes, rbenv local also works for each project.

CLI for global use

Several development CLI utilities are provided via rubygems.
You can install CLI gems locally with bundler.

Provided that CLIs should be placed under ~/bin, you can have some install directory like ~/bin/.gem/.

$ cd ~/bin/.gem/
$ bundle config bin ~/bin
$ bundle config path vendor

bundle config creates ~/bin/.gem/.bundle/config.
Put generic Gemfile in ~/bin/.gem/:

source ''

gem 'ridgepole'
gem 'pg'
gem 'solargraph'

Now, bundle install will install gems under ~/bin/.gem/vendor/ and you have CLIs in ~/bin/.

With bundler, you can install gems into specific dirs. It can be used as a dotfiles way to deploy gems.

Chuma Takahiro