How To Install Ruby on Rails on Fedora 38
In this tutorial, we will show you how to install Ruby on Rails on Fedora 38. For those of you who didn’t know, Ruby on Rails (often simply referred to as Rails) is a renowned web application framework celebrated for its efficiency and developer-friendliness. If you’re venturing into web development on Fedora 38, this guide will walk you through the intricate yet rewarding process of installing Ruby on Rails using the Command Line Interface (CLI).
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Ruby on Rails on a Fedora 38.
Prerequisites
- A server running one of the following operating systems: Fedora 38.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Ruby on Rails.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Ruby on Rails on Fedora 38
Step 1. Before we can install Ruby on Rails on Fedora 38, it’s important to ensure that our system is up-to-date with the latest packages. This will ensure that we have access to the latest features and bug fixes and that we can install Ruby on Rails without any issues:
sudo dnf update # Update the package database sudo dnf upgrade # Upgrade installed packages
Step 2. Installing Essential Packages and Dependencies
To provide a stable environment for Ruby on Rails, we need to install several essential packages and dependencies. Run these commands:
sudo dnf install curl git libffi-devel libyaml-devel readline-devel zlib-devel gdbm-devel openssl-devel libyaml-devel libffi-devel libxslt-devel libxml2-devel libcurl-devel libicu-devel sqlite-devel
This command installs essential development libraries and tools needed for building Ruby and RubyGems from the source. We’ll also need Git for version control.
Security is paramount. Create a dedicated user for your Ruby on Rails development environment:
sudo useradd -m -U -r -s /bin/bash railsdev
Step 3. Installing Ruby using RVM.
Ruby Version Manager (RVM) simplifies the management of multiple Ruby versions on your system. Let’s use it to install Ruby. First, we need to install RVM. Open your terminal and run:
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \curl -sSL https://get.rvm.io | bash -s stable
After the installation is complete, load RVM:
source ~/.rvm/scripts/rvm
Now that we have RVM installed, we can install Ruby. To install the latest stable Ruby version, use the following command:
rvm install ruby --latest
To ensure Ruby was installed successfully, check its version:
ruby -v
Step 4. Installing Rails.
Ruby on Rails is a gem, and we can install it easily using RubyGems. To install Ruby on Rails, open your terminal and run:
gem install rails
This command will download and install the latest version of Rails. It may take a few minutes to complete.
Confirm that Rails was installed correctly by checking its version:
rails -v
Step 5. Installing Node.js and Yarn for Asset Compilation.
To compile JavaScript assets in your Rails application, we need Node.js and Yarn.
To install Node.js:
sudo dnf install nodejs
Next, install Yarn:
npm install -g yarn
Step 6. Setting Up a Database.
Most web applications rely on databases. Let’s set up PostgreSQL, a popular choice for Ruby on Rails projects. Install PostgreSQL with the following command:
sudo dnf install postgresql-server postgresql-contrib
After installation, you need to initialize the PostgreSQL database cluster and start the PostgreSQL service:
sudo postgresql-setup --initdb sudo systemctl start postgresql sudo systemctl enable postgresql
Now that we have Ruby, Rails, and PostgreSQL in place, let’s create a new Rails application. Replace “myapp
” with your desired application name:
rails new myapp -d postgresql
Step 7. Configuring Your Rails Application.
Now that we have the basics set up, let’s configure your Rails application. Edit the config/database.yml
file in your Rails application directory to configure the database connection. Replace “myapp
” with your application name:
default: &default adapter: postgresql encoding: unicode host: localhost username: your_username password: your_password pool: 5
Replace your_username
and your_password
with the PostgreSQL username and password you created earlier.
Rails uses secrets to store sensitive information like API keys and database credentials securely. Run the following command to generate a secret key base:
rails secret
Then, add the generated key to your config/secrets.yml
file.
To start the Rails development server, run the following command in your application directory:
rails server
Step 8. Accessing Your Application via a Web Browser.
Open your web browser and enter http://localhost:3000
. You should see the default Rails welcome page.
Congratulations! You have successfully installed Ruby on Rails. Thanks for using this tutorial for installing Ruby on Rails on your Fedora 38 system. For additional help or useful information, we recommend you check the official Ruby on Rails website.