Tobias Erdle's Blog

Development Engineer working with different technologies. Former Jakarta MVC & Eclipse Krazo Committer. All views are my own.

Github: erdlet | E-Mail: blog (at) erdlet (punkt) de

Install Ruby and Rails on Ubuntu 22.04 LTS

Today I wanted to install Ruby 3 and Rails on an Ubuntu 22.04 LTS installation and forgot (again), which libs are required to get this done successfully. Because of that, I'll describe the correct steps in the following sections.

Step 1: Install rbenv and ruby-build

To be able to control my Ruby installation I prefer to use rbenv. With rbenv you can install different versions on Ruby and select the version to use globally or on a local base. You can install rbenv as package or from Git, which is my preferred way since the packages on Ubuntu are outdated most of the time. To install rbenv via Git and integrate it in your terminal (using ZSH in my case) run

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

echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc

in your terminal. To have access to the very helpful rbenv install command you also need to install the ruby-build plugin. It can be installed via Git by running

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

in the terminal.

Step 2: Install required libs

To be able to use rbenv install you need these libs for Ubuntu etc. which are suggested by ruby-build.

Step 3: Install Ruby

Now you can list the latest Ruby versions by running rbenv install -l and select one, e.g. 3.0.2. This version can be installed by running rbenv install 3.0.2.

Step 4: Set global Ruby version

After the successful installation of a Ruby version you can set it as global by running rbenv global 3.0.2 (or whatever version you've selected).

Step 5: Install Rails

The next step is to install the rails gem by running gem install rails in your terminal. This gem is installed for the global Ruby installation.

Step 6: Install PostgreSQL libs

In case you want to use PostgreSQL as database, you need to have at least libpq-dev installed on your system. Run sudo apt-get install libpq-dev for starting the installation. Afterwards the pg gem can be installed with gem install pg.