Install Ruby on Rails on Debian 12 Bookworm with Easy Steps
This tutorial aims to guide you through the process of installing Ruby on Rails on Debian 12 Bookworm. Ruby is a dynamic, open-source programming language known for its simplicity and productivity. Rails, often referred to as Ruby on Rails, is a powerful web application framework written in Ruby. It provides a structured approach to web development, enabling developers to build complex applications efficiently. In essence, Rails is a RubyGem, a packaged library that extends Ruby’s capabilities.
You can follow this guide to install Ruby on Rails on Debian 12 Bookworm using a command-line utility called rbenv, a tool for managing multiple Ruby versions.
Before you begin to install Ruby on Rails on Debian 12 Bookworm, ensure you meet the following prerequisites:
- You should be logged into your Debian 12 server as a non-root user with sudo privileges. Refer to a guide on Initial Server Setup with Debian 12 Bookworm for assistance.
- Node.js should be installed and running on your server. Consult a guide on Setting up Node.js LTS on Debian 12 Bookworm for instructions.
Once these requirements are fulfilled, proceed with the steps below to install Ruby on Rails on Debian 12 Bookworm.

Step 1 – Download and Install rbenv on Debian 12
rbenv is a command-line tool that simplifies the process to install Ruby on Rails on Debian 12 Bookworm, manage, and switch between multiple Ruby environments. Follow these steps to install rbenv:
First, update the system package list:
sudo apt update
Next, install the necessary dependencies:
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev -y
Now, use the following curl command to download the rbenv installer script from GitHub and execute it using bash
:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Add ~/.rbenv/bin
to your $PATH
environment variable:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
Configure rbenv to load automatically:
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Apply the changes by sourcing the .bashrc
file:
source ~/.bashrc
Verify that rbenv is functioning correctly:
type rbenv
**<mark>Output</mark>**
rbenv is a function
rbenv ()
{
local command;
command="${1:-}";
if [ "$#" -gt 0 ]; then
shift;
fi;
case "$command" in
rehash | shell)
eval "$(rbenv "sh-$command" "$@")"
;;
*)
command rbenv "$command" "$@"
;;
esac
}
Step 2 – Install Ruby with rbenv on Debian 12 Bookworm
With rbenv installed, you can now install Ruby on Rails on Debian 12 Bookworm. First, list the available Ruby versions:
rbenv install -l
**<mark>Output</mark>**
3.0.6
3.1.4
3.2.2
jruby-9.4.3.0
mruby-3.2.0
picoruby-3.0.0
truffleruby-23.0.0
truffleruby+graalvm-23.0.0
Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all / -L' to show all local versions.
Install the latest stable Ruby version (e.g., 3.2.2):
rbenv install 3.2.2
This process may take some time.
Set the newly installed Ruby version as the global default:
rbenv global 3.2.2
Verify the Ruby installation by checking the version:
ruby -v
**<mark>Output</mark>**
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
Step 3 – Install Rails on Debian 12 Bookworm
Gems are packages containing Ruby libraries. Use the gem
command to manage Ruby gems and install Rails. Also, install Bundler, a tool for managing gem dependencies.
Execute the following commands:
# echo "gem: --no-document" > ~/.gemrc
# gem install bundler
**<mark>Output</mark>**
Fetching bundler-2.4.19.gem
Successfully installed bundler-2.4.19
1 gem installed
Verify where gems are being installed:
gem env home
**<mark>Output</mark>**
/root/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0
Install the latest version of Rails on Debian 12 Bookworm:
gem install rails
**<mark>Output</mark>**
...
Successfully installed rails-7.0.8
36 gems installed
Note: To install a specific Rails version, use the following commands:
# gem search '^rails$' --all
# gem install rails -v your-desired-version
After installing a new Ruby version or a gem that provides commands (like Rails), run:
rbenv rehash
Verify the Rails installation:
rails -v
**<mark>Output</mark>**
Rails 7.0.8
Step 4 – Update rbenv Tool on Debian 12
Update rbenv using git pull
. Navigate to the ~/.rbenv
directory and run:
# cd ~/.rbenv
# git pull
Step 5 – Uninstall Ruby Versions on Debian 12
To uninstall a specific Ruby version, use:
rbenv uninstall 3.2.1
Step 6 – Uninstall rbenv from Debian 12
To remove rbenv, follow these steps:
Open the ~/.bashrc
file with a text editor (e.g., vi
):
vi ~/.bashrc
Remove the following lines:
...
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Save and close the file.
Remove rbenv and all installed Ruby versions:
rm -rf `rbenv root`
For further information, refer to the Rails Guides on the official site.
Conclusion
This guide has demonstrated how to use rbenv to manage Ruby environments and install Ruby on Rails on Debian 12 Bookworm step by step.
Hopefully, you found this guide on how to install Ruby on Rails on Debian 12 Bookworm helpful. You might also be interested in:
PHP Composer Installation Guide on Debian 12 Bookworm
Froxlor Server Management Software on Debian 12 Bookworm
Alternative Solutions for Installing Ruby on Rails on Debian 12 Bookworm
While rbenv is a popular and effective tool, there are alternative methods for installing Ruby on Rails on Debian 12 Bookworm. Here are two different approaches:
1. Using RVM (Ruby Version Manager)
RVM is another Ruby version manager similar to rbenv. It offers a slightly different approach to managing Ruby environments and is also widely used.
-
Explanation: RVM provides a more comprehensive environment management system compared to rbenv. It can handle gemsets, which allow you to isolate gem dependencies for different projects more effectively. This is beneficial when working on multiple Rails applications with potentially conflicting gem requirements.
-
Installation and Usage:
First, install the required dependencies:
sudo apt update sudo apt install curl gpg2
Then, import RVM’s GPG key:
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Install RVM:
curl -sSL https://get.rvm.io | bash -s stable
You may need to restart your terminal or source the RVM script:
source ~/.rvm/scripts/rvm
List available Ruby versions:
rvm list known
Install a specific Ruby version (e.g., 3.2.2):
rvm install 3.2.2
Set the default Ruby version:
rvm use 3.2.2 --default
Finally, install Rails:
gem install rails
2. Using asdf Version Manager
asdf is a versatile version manager that supports multiple languages, including Ruby. It provides a unified interface for managing different language runtimes and their associated tools.
-
Explanation: asdf offers a consistent experience for managing versions across various languages. This can be particularly useful if you work with projects that involve multiple languages and need a single tool to manage their respective runtimes.
-
Installation and Usage:
First, install the required dependencies:
sudo apt update sudo apt install git curl
Install asdf:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc echo 'alias asdf=". $HOME/.asdf/asdf.sh"' >> ~/.bashrc source ~/.bashrc
Add the Ruby plugin:
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
Install required dependencies for Ruby (using the asdf-ruby plugin’s instructions, which may vary):
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev
List available Ruby versions:
asdf list-all ruby
Install a specific Ruby version (e.g., 3.2.2):
asdf install ruby 3.2.2
Set the local Ruby version for your project:
asdf local ruby 3.2.2
Or set the global version:
asdf global ruby 3.2.2
Install Rails:
gem install rails
These alternative solutions offer different approaches to managing Ruby versions and dependencies, allowing you to choose the method that best suits your workflow and project requirements to install Ruby on Rails on Debian 12 Bookworm.