This article is a tutorial for to install the Ruby on Fedora 27 and 28 by the rbenv together with some of its plugins.

Install the Ruby from official Fedora packages, isn’t a very good solution in my opinion, for usually these packages aren’t updated on the same velocity of new Ruby versions are release, another issue is that on much cases is necessary works simutally with distincts Ruby version, as solution to the cited issues we can use the rbenv to install and manage the Ruby versions.

Install the requirements

Firstly is necessary to install the requirements.

sudo dnf install -y git gcc-c++ bzip2 openssl-devel libyaml-devel \
  libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel

Install the rbenv

Every commands not should be executed as super user.

We’ll use the Git, to clone the rbenv to default install directory.

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Optionally you can run the below command to improve the rbenv performance, but don’t sweat if something fail, all continues working normally, just go to next step.

cd ~/.rbenv && src/configure && make -C src

Install rbenv plugins

The rbenv has diverse plugins that facilities its use, among them I chose 2 that are indispensable in my opinion, which can be installed follow the guide below, you can finding more plugins here.

Install the ruby-build

The ruby-build automatize the installation of Ruby, is possible use it separately or together with the rbenv transparently.

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Install the rbenv-default-gems

The rbenv-default-gems install automatically the gems defined at file ~/.rbenv/plugins/rbenv-default-gems always that a new Ruby version is installed.

git clone https://github.com/rbenv/rbenv-default-gems.git ~/.rbenv/plugins/rbenv-default-gems

Configure the rbenv on Shell

With the rbenv and plugins installed, now is necessary to include it on $PATH and then integrate it with the shell, case you not use the bash as shell, you should to change the ~/.bashrc to file that is read by your shell on session start, as for example at case of the zsh would be necessary to change ~/.bashrc to ~/.zshrc.

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Now restart the session with shell, for do it close and then open your terminal, or run the command below, remembering that the command only works for the bash.

source ~/.bashrc

Install the Ruby

We’ll installing the version 2.5.1, because at moment that this article being writing, this is the more recent stable version, this step can be take some minutes, so just waiting paciently the download and installation.

rbenv install 2.5.1

The Ruby was installed, now is needed to use the rbenv to define which version of Ruby we want to use, we can to define a global version and/or to define especifical versions for the directories that we wish.

For define the version 2.5.1 as global, run.

rbenv global 2.5.1

For to use the version 2.5.1 in a specific directory independently of global version, inside the chosen directory, run.

rbenv local 2.5.1

The command above will create the hidden file .ruby-version which containing the Ruby version that should be utilized in this directory and in its subdirectories,when the rbenv find this file its will ignore the global version and will automatically to change version of the Ruby to version defined in the file.

In both cases, firstly is needed to install the Ruby version wished, because the commands global and local just changes the version in use, they don’t installation.

For to know which Ruby version is in use, run.

ruby --version

With this we come to the end of this tutorial, now your Fedora supports multiple versions of Ruby simultaneously.

Resources