I recently tried to Install Ruby on Rails on Debian 12 for a project, and while I eventually got it working, the process was far from smooth. Here’s what I did, along with the issues I faced, in case it helps others avoid the same pitfalls.
Step 1: Install Ruby
I started by installing Ruby using the default package manager, but ran into version issues. The default Ruby version on Debian 12 was too old for Rails, so I had to remove it and install a newer version using rbenv
. Here’s what I did:
-
Remove the default Ruby (if installed):
sudo apt remove ruby
-
Install dependencies for rbenv:
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libncurses5-dev libffi-dev libgdbm-dev
-
Install rbenv and Ruby:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-installer | bash echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc rbenv install 3.2.2 # Replace with the version you need rbenv global 3.2.2
Problem: After installing Ruby, running
ruby -v
gave me an error about missing libraries. I had to manually installlibssl-dev
andlibreadline-dev
to fix it.
Step 2: Install Rails
Once Ruby was installed, I tried to install Rails using gem install rails
, but it failed due to permission issues. Here’s how I fixed it:
-
Install Rails:
gem install rails
Problem: The command failed with a permission error. I had to use
--user-install
to install Rails locally:gem install rails --user-install
-
Add gems to PATH:
I added the following to my.bashrc
to ensure Rails commands were recognized:export PATH="$HOME/.gem/ruby/3.2.2/bin:$PATH" source ~/.bashrc
Step 3: Set Up a Rails Project
I created a new Rails project, but ran into database configuration issues:
-
Create a new project:
rails new myapp
Problem: The
rails new
command failed becausebundler
wasn’t installed. I had to install it manually:gem install bundler
-
Install dependencies:
After fixingbundler
, I ran:bundle install
Problem: The
pg
gem (for PostgreSQL) failed to install because I didn’t have the PostgreSQL development libraries. I fixed it by running:sudo apt install libpq-dev
Step 4: Run the Rails Server
Finally, I tried to run the Rails server, but it wouldn’t start:
-
Start the server:
rails server
Problem: The server failed to start because JavaScript runtime was missing. I installed Node.js to fix it:
sudo apt install nodejs
Conclusion
While I eventually managed to Install Ruby on Rails on Debian 12, the process was frustrating due to missing dependencies and permission issues. If you’re trying this, make sure to:
- Use
rbenv
for Ruby installation. - Install all necessary development libraries (e.g.,
libssl-dev
,libpq-dev
,nodejs
). - Use
--user-install
if you encounter permission errors.