How to install Ruby on Rails with rbenv on Ubuntu 22.04
rbenv is a tool for managing multiple versions of Ruby on the same system. It allows you to install, change, and manage different versions of Ruby, which is useful for projects that require specific versions of Ruby or for working with different projects that use different versions of Ruby. Additionally, rbenv can integrate with other tools and plugins to facilitate the installation of Ruby versions and manage specific gems for each project.
Below we show you a detailed manual on how to install Ruby on Rails with rbenv on Ubuntu 22.04:
1. Update the system
Before starting to install Ruby on Rails, it is important to ensure that the system is updated. To do this, open a terminal and run the following commands:
sudo apt update
sudo apt upgrade
2. Install the necessary dependencies
To be able to compile Ruby and some Rails gems, you will need to install some dependencies. Run the following command to install them:
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool pkg-config sqlite3 nodejs npm
3. Install rbenv
To install rbenv, run the following commands:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
4. Install ruby-build
ruby-build is an rbenv plugin that allows you to install different versions of Ruby. To install it, run the following commands:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
5. Install Ruby
Once rbenv and ruby-build are installed, you can install the Ruby version you want. For example, to install Ruby 3.1.0, run the following command:
rbenv install 3.1.0
Once the installation is complete, make sure to set the newly installed Ruby version as the default rbenv version:
rbenv global 3.1.0
6. Install Rails
Finally, you can install Rails by running the following command:
gem install rails
7. Verify the installation
To verify that everything has been installed correctly, run the following commands:
ruby -v
rails -v
These commands should show the installed version of Ruby and Rails on your system.
success Done! You now have Ruby on Rails installed on Ubuntu 22.04 with rbenv.