Installing Ruby on Ubuntu Using rbenv

Techie     January 2023

Introduction

rbenv is a ruby version management tool designed to manage multiple versions of Ruby on the same device and lets you easily switch between them.


1 . Install dependencies for compiiling Ruby

$ sudo apt update && sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev dirmngr gnupg apt-transport-https ca-certificates


2 . Install rbenv

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

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc

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

$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc

$ git clone https://github.com/rbenv/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars

$ exec $SHELL


3 . Install Ruby

Install a Ruby version of your choice. e.g 3.2.0

$ rbenv install 3.2.0

# Make it the default version
$ rbenv global 3.2.0

# Confirm instllation
$ ruby -v

# ruby 3.2.0


4 . Install Bundler

# install the latest version
$ gem install bundler


# or you can install a version of your choice
$ gem install bundler -v 1.17.3


$ rbenv rehash


# See if it is installed

$ bundler -v

# Bundler version 2.3.26


Thanks for reading, see you in the next one!