How to install Ruby on Rails with rbenv on Ubuntu 22.04
rbenv is a tool for managing multiple versions of Ruby on a single system. It allows you to install, switch 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. In addition, rbenv can be integrated with other tools and plugins to make it easy to install Ruby versions and manage project-specific gems.
Below is a detailed manual on how to install Ruby on Rails with rbenv on Ubuntu 22.04:
1. Update your system
Before you start installing Ruby on Rails, it's important to make sure your system is up to date. To do this, open a terminal and run the following commands:
sudo apt update
sudo apt upgrade
2. Install the necessary dependencies
In order to compile Ruby and some Rails gems, you'll 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 version of Ruby you want. For example, to install Ruby 3.1.0, run the following command:
rbenv install 3.1.0
Once the installation is complete, be sure to set the newly installed version of Ruby as the default version of rbenv:
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 version of Ruby and Rails installed on your system.
success That's it! You now have Ruby on Rails installed on Ubuntu 22.04 with rbenv.