Guides 11792 Published by

The article walks through setting up a fresh Rails environment on Debian 11 by first updating the system and installing essential build libraries before cloning rbenv and its ruby‑build plugin. It then shows how to install Ruby 3.2, upgrade bundler, and finally pull in the latest Rails release, with verification commands to confirm everything is wired correctly. A quick sanity test creates a new application, skips initial bundle for speed, runs the server, and points out that the welcome page should appear at localhost:3000. The guide also warns about a common SQLite3 build error and offers a simple fix, concluding by recommending rbenv as the cleanest way to manage Ruby versions on Debian.



Install Ruby on Rails on Debian 11

If you’re setting up a new dev box or just want to experiment, installing Rails on Debian 11 can feel like an exercise in patience. Below is a quick‑fire guide that gets the stack working without pulling out your hair.

Why the default packages aren’t enough

Debian 11 ships Ruby 2.7 with apt, but it’s missing several gems and bundler tooling that Rails expects today. I’ve seen developers hit a wall when they run rails new myapp right after installing from APT: “Bundler::GemNotFound – Could not find rails (6.1.4) in any repository.” That’s why we’ll use rbenv to install the latest stable Ruby and then pull in Rails with Bundler.

Install prerequisites
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential libssl-dev zlib1g-dev \
    libreadline-dev libyaml-dev libxml2-dev libxslt1-dev \
    libcurl4-openssl-dev libffi-dev git curl

Why? These libraries let the Ruby interpreter compile and run without hiccups. Skipping them will force you to wrestle with missing dependencies later.

Install rbenv & ruby-build
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Why? rbenv gives you multiple Ruby versions side‑by‑side. ruby-build is a plugin that installs them for you.

Install the latest stable Ruby
rbenv install 3.2.0
rbenv global 3.2.0

Why? Rails 7 needs Ruby >= 3.1, so we pick a current LTS version. The global command ensures every shell you open uses it.

Make sure bundler is up‑to‑date
gem install bundler
rbenv rehash

Why? Bundler orchestrates gem dependencies for Rails projects. A stale bundler can misbehave when resolving the rails gem itself.

Install Rails
gem install rails
rbenv rehash

Why? This pulls the latest stable Rails release and hooks it into your shell with rbenv.

Verify everything is wired up
ruby -v      # should print ruby 3.2.0
rails -v     # should print Rails 7.x.x

If you see those numbers, you’re good to go.

Quick sanity test

Create a fresh app and run its built‑in server:

mkdir ~/myrails && cd ~/myrails
rails new demo_app --skip-bundle   # we’ll bundle ourselves later
cd demo_app
bundle install
rails s -b 0.0.0.0 -p 3000

Open http://localhost:3000 – you should see the Rails welcome page.

Why skip‑bundle? The first rails new step installs a large set of gems that might already be available from the system cache; skipping it speeds up setup when you’re in a hurry.

Common hiccup: “Gem::Ext::BuildError” on sqlite3

If you run into errors compiling SQLite bindings, add:

sudo apt install -y libsqlite3-dev
gem uninstall sqlite3 && gem install sqlite3 -- --with-sqlite3-dir=/usr/include/x86_64-linux-gnu

Why? Debian’s bundled libsqlite3.so is a bit old for newer Ruby gems. Installing the dev headers gives the native extension what it needs.

Wrap‑up

You’ve got a working Rails installation on Debian 11 without digging into the abyss of system packages. Stick with rbenv; it keeps your Ruby world tidy and lets you upgrade or switch versions in seconds.