Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 2446

General discussion • How to Install Ruby on Rails on Debian 12: A Step-by-Step Guide

$
0
0
How to Install Ruby on Rails on Debian 12: A Step-by-Step Guide

Ruby on Rails is a powerful web development framework that allows you to build modern web applications quickly. If you’re using Debian 12 and want to set up Ruby on Rails, this guide will walk you through the process step by step. By the end, you’ll have a fully functional Rails environment ready for development.
Prerequisites

Before you begin, ensure you have:

A system running Debian 12.

sudo privileges to install packages.

An active internet connection.

Step 1: Update Your System

Start by updating your system to ensure all packages are up to date:
bash
Copy

sudo apt update && sudo apt upgrade -y

Step 2: Install Dependencies

Ruby on Rails requires several dependencies. Install them using the following command:
bash
Copy

sudo apt install curl git build-essential libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev

Step 3: Install Ruby Using rbenv

To avoid conflicts with the system Ruby, we’ll use rbenv to install and manage Ruby versions.

Install rbenv and ruby-build:
bash
Copy

curl -fsSL https://github.com/rbenv/rbenv-installe ... -installer | bash

Add rbenv to your shell:
Add the following lines to your ~/.bashrc file:
bash
Copy

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Then, reload your shell:
bash
Copy

source ~/.bashrc

Install Ruby:
Install the latest stable version of Ruby (e.g., Ruby 3.2.2):
bash
Copy

rbenv install 3.2.2
rbenv global 3.2.2

Verify the installation:
bash
Copy

ruby -v

You should see the installed Ruby version.

Step 4: Install Rails

With Ruby installed, you can now install Rails:
bash
Copy

gem install rails

Verify the installation:
bash
Copy

rails -v

Step 5: Set Up a Database

Rails applications typically use a database. Install MySQL or PostgreSQL based on your preference.
Option 1: Install MySQL
bash
Copy

sudo apt install mysql-server libmysqlclient-dev

Configure MySQL and create a database for your Rails app.
Option 2: Install PostgreSQL
bash
Copy

sudo apt install postgresql postgresql-contrib libpq-dev

Set up a PostgreSQL user and database for your Rails app.
Step 6: Create a New Rails Application

Now that everything is set up, create a new Rails application:
bash
Copy

rails new myapp -d mysql # Use `postgresql` if you installed PostgreSQL
cd myapp

Step 7: Configure the Database

Edit the config/database.yml file to match your database settings. For example, for MySQL:
yaml
Copy

default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password: yourpassword
socket: /var/run/mysqld/mysqld.sock

Run the database setup:
bash
Copy

rails db:setup

Step 8: Start the Rails Server

Finally, start the Rails server:
bash
Copy

rails server

Visit http://localhost:3000 in your browser to see your Rails app in action!
Troubleshooting Common Issues

Ruby Installation Fails:
Ensure all dependencies are installed and try again.

Database Connection Issues:
Double-check your database.yml file and ensure the database service is running.

Permission Errors:
Use sudo where necessary or adjust file permissions.

Why Install Ruby on Rails on Debian 12?

Debian 12 is a stable and secure operating system, making it an excellent choice for hosting Ruby on Rails applications. By following this guide, you can set up a robust development environment that’s ready for building modern web applications.
Conclusion

If you’re looking to Install Ruby on Rails on Debian 12, this guide provides a clear and actionable roadmap. Whether you’re a beginner or an experienced developer, this setup will provide a solid foundation for your Rails projects. If you found this guide helpful, feel free to share it and link back to it for others who want to Install Ruby on Rails on Debian 12.

Statistics: Posted by phpguider — Sat Mar 22, 2025 10:43 am



Viewing all articles
Browse latest Browse all 2446

Trending Articles