Share your love
Install Ruby on Rails on Debian 12 Bookworm with Easy Steps
This tutorial intends to teach you to Steps To Install Ruby on Rails on Debian 12 Bookworm. Ruby is an open-source software that is used to build a web app. Rails is the framework written in the Ruby language that is used for server-side web development. Also, it can be defined as a library package called RubyGem.
You can follow this guide from the Orcacore website to Install Ruby on Rails on Debian 12 Bookworm by using a command line utility called rbenv.
Table of Contents
Step To Install Ruby on Rails on Debian 12 Bookworm
Before you start to Install Ruby on Rails on Debian 12 Bookworm, you need some requirements for it.
First, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.
Then, you must have Node.js running on your server. For this purpose, you can check this guide on Setting up Node.js LTS on Debian 12 Bookworm.
When you are done, follow 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 allows you to easily Install Ruby on Rails on Debian 12 Bookworm, manage, and work with multiple Ruby environments. To install it, follow the steps below:
First, run the system update with the command below:
sudo apt update
Then, use the command below to install the required packages:
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
At this point, you can use the following curl command to download the rbenv installer script from GitHub and pipe it directly to bash
to run the installer:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Then, you need to add ~/.rbenv/bin
to your $PATH
. To do this, you can use the following command:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
To load the rbenv automatically, you need to run the following command:
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Next, source the bashrc to apply the changes:
source ~/.bashrc
Verify that your rbenv tool is working correctly on Debian 12 by using the command below:
type rbenv
Output
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
At this point, you can use the rbenv tool to Install Ruby on Rails on Debian 12 Bookworm. First, list available Ruby versions on Debian 12:
rbenv install -l
Output
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.
As you can see, the latest stable release of Ruby is 3.2.2. To install it, you can easily run the command below:
rbenv install 3.2.2
This may take some time to complete.
Then, you can set your Ruby version as your default with the command below:
rbenv global 3.2.2
Verify your Ruby installation by checking its version:
ruby -v
Output
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
Step 3 – Install Rails on Debian 12 Bookmorm
Gems are the way Ruby libraries are distributed. At this point, you can use the gem command to manage Ruby gems and install Rails on your server. Also, install Bundler which is a tool for managing gem dependencies for projects.
To do these, you can run the commands below:
# echo "gem: --no-document" > ~/.gemrc
# gem install bundler
Output
Fetching bundler-2.4.19.gem
Successfully installed bundler-2.4.19
1 gem installed
Verify where gems are being installed by using the command below:
gem env home
Output
/root/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0
Now you can use the command below to install the latest Rails on Debian 12 Bookworm:
gem install rails
Output
...
Successfully installed rails-7.0.8
36 gems installed
Note: If you would like to install a specific version of Rails, you can list the version and install it by using the commands below:
# gem search '^rails$' --all
# gem install rails -v your-desired-version
Whenever you install a new version of Ruby or a gem that provides commands as Rails does, you should run the following command:
rbenv rehash
Verify your Rails installation by checking its version:
rails -v
Output
Rails 7.0.8
Step 4 – Update rbenv Tool on Debian 12
You can easily update your rbenv tool by using the git pull command. Switch to your ~/.rbenv directory and run the following command:
# cd ~/.rbenv
# git pull
Step 5 – Uninstall Ruby Versions on Debian 12
If you have downloaded additional versions of Ruby, you can easily use the command below to uninstall the specific version. For example:
rbenv uninstall 3.2.1
Step 6 – Uninstall rbenv from Debian 12
If you don’t want to use the rbenv tool anymore, you can follow the steps below to remove it.
First, open your ~/.bashrc file with your favorite text editor, here we use the vi editor:
Find and remove the following two lines from the file:
vi ~/.bashrc
...
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
When you are done, save and close the file.
Then remove rbenv and all installed Ruby versions with the following command:
rm -rf `rbenv root`
For more details and information, you can visit this link for Rails Guides from the official site.
Conclusion
At this point, you have learned to use the rbenv tool which is for managing the Ruby environments to Install Ruby on Rails on Debian 12 Bookworm step by step.
Hope you enjoy this guide on Install Ruby on Rails on Debian 12 Bookworm. Also, you may interested in these articles: