How to Install Ruby on Rails on Debian 12
If you’re looking to Install Ruby on Rails on Debian 12, you’re in the right place! Ruby on Rails is a powerful framework for building web applications, and setting it up on Debian 12 is straightforward. Here’s how I did it: Step 1: Update Your System
Before installing anything, update 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: bash Copy
sudo apt install curl git build-essential libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev
Step 3: Install Ruby Using rbenv
The default Ruby version on Debian 12 might be outdated, so we’ll use rbenv to install and manage Ruby versions:
Install rbenv and ruby-build:
bash
Copy
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-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 give you 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.
All rights reserved