DebianDebian Based

How To Install Ruby on Rails on Debian 13

Install Ruby on Rails on Debian 13

Installing Ruby on Rails on Debian 13 provides developers with a powerful web application framework built on the Ruby programming language. Rails follows the Model-View-Controller (MVC) architecture and embraces the “Convention over Configuration” philosophy, making it an excellent choice for rapid web development. This comprehensive guide covers multiple installation methods to ensure you can successfully set up Ruby on Rails on your Debian 13 system, whether you’re a beginner developer or an experienced system administrator.

Understanding Ruby on Rails and Debian 13

What is Ruby on Rails?

Ruby on Rails, commonly referred to as Rails, is an open-source web application framework written in Ruby. The framework implements the Model-View-Controller (MVC) architectural pattern, which separates application logic into three interconnected components. This separation enhances code organization and maintainability.

Rails operates on the Convention over Configuration (CoC) principle, reducing the number of decisions developers need to make while maintaining flexibility. Popular applications built with Rails include GitHub, Shopify, Basecamp, and Airbnb, demonstrating its capability for handling large-scale web applications.

Debian 13 Compatibility

Debian 13 provides excellent compatibility with Ruby and Rails installations. The operating system offers robust package management through APT, comprehensive dependency resolution, and strong security features that make it ideal for development environments.

Modern Debian systems support both x86_64 and ARM architectures, ensuring compatibility across various hardware configurations. The stable nature of Debian makes it particularly suitable for both development and production Rails deployments.

Prerequisites and System Preparation

System Requirements

Before beginning the installation process, ensure your Debian 13 system meets the minimum requirements. You’ll need at least 2GB of RAM, though 4GB or more is recommended for optimal performance. Sufficient disk space is essential—allocate at least 5GB for the Rails installation and associated dependencies.

Verify your Debian 13 installation by running lsb_release -a in the terminal. Ensure you have a stable network connection for downloading packages and dependencies. Root or sudo access is required for installing system packages.

Essential Dependencies

Ruby on Rails requires several system dependencies for compilation and proper functionality. These include build tools, SSL/TLS libraries, YAML development libraries, and database support packages.

The essential packages include build-essential for compilation tools, libssl-dev for SSL support, libyaml-dev for YAML parsing, libreadline-dev for readline functionality, and zlib1g-dev for compression support. Additionally, install git for version control and curl for downloading installation scripts.

Installation Methods Overview

Available Installation Approaches

Several methods exist for installing Ruby on Rails on Debian 13. The package manager approach uses APT to install system packages, which is simple but may provide older versions. Ruby Version Manager (RVM) offers version management capabilities but has fallen out of favor due to complexity.

The rbenv method provides lightweight Ruby version management without shell modification. Mise represents the modern approach, supporting multiple runtime environments with excellent performance and user experience.

Recommended Method Selection

Mise stands out as the recommended installation method for modern Ruby on Rails development. It provides superior version management, faster performance compared to traditional version managers, and support for multiple programming languages beyond Ruby.

Mise offers automatic version switching based on project configuration, minimal shell overhead, and excellent compatibility with modern development workflows. For production environments, consider using system packages, while development environments benefit from version managers like Mise.

Method 1: Installing Ruby on Rails Using Mise (Recommended)

Installing System Dependencies

Begin by updating your package lists to ensure you have access to the latest package versions:

sudo apt update && sudo apt upgrade -y

Install the essential build tools and development libraries required for Ruby compilation:

sudo apt install -y build-essential libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev libdb-dev curl git

These packages provide the foundation for compiling Ruby from source and ensure all dependencies are available. The build-essential package includes GCC, make, and other compilation tools. SSL libraries enable secure connections, while YAML libraries support Rails configuration files.

Verify the installation by checking the availability of essential tools:

gcc --version
make --version
curl --version

Installing Mise Version Manager

Download and install Mise using the official installation script:

curl https://mise.run | sh

The installation script automatically detects your shell configuration and provides appropriate setup instructions. For Bash users, add Mise to your shell configuration:

echo 'eval "$(~/.local/bin/mise activate bash)"' >> ~/.bashrc
source ~/.bashrc

For Zsh users, modify the .zshrc file instead:

echo 'eval "$(~/.local/bin/mise activate zsh)"' >> ~/.zshrc
source ~/.zshrc

Verify the Mise installation by checking its version and available commands:

mise --version
mise help

Installing Ruby with Mise

Install the latest Ruby version using Mise’s global configuration:

mise use -g ruby@latest

This command downloads, compiles, and installs the most recent stable Ruby version. The compilation process may take several minutes depending on your system’s performance. Mise automatically handles dependency resolution and optimization flags.

Verify the Ruby installation:

ruby --version
which ruby

The output should display the Ruby version and confirm it’s managed by Mise. Check that essential Ruby components are available:

gem --version
irb --version

Installing Bundler and Updating RubyGems

Update RubyGems to the latest version for improved package management:

gem update --system

Install Bundler, the essential dependency management tool for Ruby applications:

gem install bundler

Bundler manages gem dependencies for individual projects, ensuring consistent environments across different systems. Verify the Bundler installation:

bundler --version

Configure Bundler for optimal performance by setting parallel job execution:

bundle config --global jobs 4

Installing Ruby on Rails

With Ruby and Bundler properly configured, install the Rails framework:

gem install rails

The Rails installation includes numerous dependencies and may take several minutes. Once complete, verify the installation:

rails --version

Rails also installs several command-line utilities. Check their availability:

which rails
rails help

Method 2: Installing Ruby on Rails Using rbenv

Installing rbenv Dependencies

For systems preferring rbenv over Mise, begin with installing the required dependencies:

sudo apt update
sudo apt install -y git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev

These packages ensure rbenv can compile Ruby versions from source. The additional packages support various Ruby extensions and libraries commonly used in Rails applications.

Installing rbenv

Clone the rbenv repository to your home directory:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv

Add rbenv to your PATH by modifying your shell configuration:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

Install the ruby-build plugin for building Ruby versions:

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

Verify rbenv installation:

rbenv --version

Installing Ruby and Rails with rbenv

List available Ruby versions:

rbenv install --list

Install the latest stable Ruby version (replace X.X.X with the actual version):

rbenv install 3.2.0
rbenv global 3.2.0

Verify the Ruby installation:

ruby --version
gem --version

Install Rails using gem:

gem install rails
rbenv rehash

The rbenv rehash command updates rbenv’s knowledge of installed gems with executables.

Method 3: Installing Using RVM (Ruby Version Manager)

RVM Prerequisites and GPG Setup

Install packages required for RVM functionality:

sudo apt install -y curl gpg

Import the RVM GPG keys for security verification:

gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

This step ensures the authenticity of the RVM installation script and protects against potential security threats.

Installing RVM

Download and install RVM with the latest stable Ruby:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

Load RVM into your current shell session:

source ~/.rvm/scripts/rvm

Add RVM to your shell configuration for automatic loading:

echo 'source ~/.rvm/scripts/rvm' >> ~/.bashrc

Ruby and Rails Installation via RVM

List available Ruby versions:

rvm list known

Install a specific Ruby version and set it as default:

rvm install 3.2.0
rvm use 3.2.0 --default

Install Rails:

gem install rails

Installing and Configuring Rails Framework

Rails Installation Process

Regardless of your chosen Ruby installation method, installing Rails follows the same process. Use RubyGems to install the latest Rails version:

gem install rails --no-document

The --no-document flag skips documentation generation, reducing installation time. For development purposes, you might prefer including documentation:

gem install rails

Verify the Rails installation and check available generators:

rails --version
rails generate --help

Rails Configuration and Setup

Rails includes several configuration options that optimize development workflow. Create a global Rails configuration directory:

mkdir -p ~/.rails

Configure Rails to use your preferred database adapter, text editor, and testing framework. These preferences apply to all new Rails applications you generate.

Database Setup and Configuration

SQLite Setup (Default)

Rails uses SQLite as the default database for development environments. Install the SQLite development libraries:

sudo apt install -y libsqlite3-dev sqlite3

SQLite requires no additional configuration for development use. Rails automatically creates database files in your project’s db/ directory. Verify SQLite functionality:

sqlite3 --version

PostgreSQL Integration (Optional)

For applications requiring PostgreSQL, install the database server and development libraries:

sudo apt install -y postgresql postgresql-contrib libpq-dev

Create a PostgreSQL user for your Rails applications:

sudo -u postgres createuser -s $(whoami)
sudo -u postgres createdb $(whoami)

Configure your Rails applications to use PostgreSQL by modifying the database.yml file or generating new applications with the PostgreSQL adapter:

rails new myapp --database=postgresql

Creating Your First Rails Application

Application Generation

Create a new Rails application to test your installation:

rails new testapp
cd testapp

Rails generates a complete application structure with sensible defaults. The generation process creates directories for models, views, controllers, configuration files, and assets.

Examine the generated structure:

ls -la
cat Gemfile

Running the Development Server

Start the Rails development server:

rails server

Alternatively, use the shorter command:

rails s

The server starts on http://localhost:3000 by default. Open your web browser and navigate to this address to see the Rails welcome page. This confirms your installation is working correctly.

Install Ruby on Rails on Debian 13

Stop the server by pressing Ctrl+C in the terminal.

Verification and Testing

Installation Verification

Confirm all components are properly installed by checking versions:

ruby --version
rails --version
bundler --version
gem --version

Create a simple controller to test basic functionality:

cd testapp
rails generate controller Welcome index

Modify the routes file to set the welcome page as root:

# config/routes.rb
Rails.application.routes.draw do
  root 'welcome#index'
end

Basic Functionality Testing

Start the Rails server and verify the custom welcome page loads correctly. Create a simple model to test Active Record functionality:

rails generate model Article title:string content:text
rails db:migrate

Test the model in the Rails console:

rails console
Article.create(title: "Test", content: "This is a test article")
Article.all
exit

These commands verify that Rails can generate code, manage databases, and provide interactive console access.

Troubleshooting Common Issues

Installation Problems

Permission denied errors: Avoid using sudo with gem installations when using version managers. If you encounter permission issues, check that your version manager is properly configured and activated.

Missing dependencies: Install additional development packages if Ruby compilation fails:

sudo apt install -y autoconf bison libssl-dev libyaml-dev libreadline-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev

Network connectivity issues: Configure proxy settings if behind corporate firewalls. Set environment variables for HTTP_PROXY and HTTPS_PROXY as needed.

Runtime Issues

Server startup failures: Check that no other services are using port 3000. Start the server on a different port if necessary:

rails server -p 3001

Database connection problems: Verify database services are running and connection parameters are correct. For PostgreSQL issues, check service status:

sudo systemctl status postgresql

Asset compilation errors: Ensure Node.js is installed for JavaScript asset processing:

sudo apt install -y nodejs npm

Best Practices and Security Considerations

Development Environment Security

Configure your development environment with security in mind. Avoid running development servers as root. Use environment variables for sensitive configuration data rather than hardcoding values in application files.

Keep your Ruby version manager and Rails framework updated to receive security patches. Regularly update gems using bundle update for project-specific dependencies or gem update for global gems.

Performance Optimization

Choose appropriate Ruby versions based on performance benchmarks and compatibility requirements. Ruby 3.x offers significant performance improvements over earlier versions. Configure your development environment with adequate system resources.

Use local caching for development databases and configure asset pipeline optimization. Consider using solid-state drives for improved file system performance, especially during asset compilation and test suite execution.

Updating and Maintenance

Keeping Ruby and Rails Updated

Version managers make updating Ruby straightforward. With Mise, upgrade to newer Ruby versions:

mise install ruby@3.2.1
mise use -g ruby@3.2.1

Update Rails to newer versions carefully, considering compatibility with your existing applications:

gem update rails

Environment Management

Use project-specific Ruby versions by creating .ruby-version files in your project directories. This ensures consistent environments across team members and deployment targets.

Configure Bundler to use project-local gem installations:

bundle config set --local path 'vendor/bundle'
bundle install

This approach isolates project dependencies and prevents version conflicts between applications.

Congratulations! You have successfully installed Ruby on Rails. Thanks for using this tutorial for installing Ruby on Rails application framework on the Debian 13 “Trixie” system. For additional help or useful information, we recommend you check the official Ruby on Rails website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button