Ruby on Rails

How to Install Ruby on Rails on Arch Linux with RVM

If you’re looking to get started with Ruby on Rails (RoR) on your Arch Linux system, you’ve made a great choice. Rails is a powerful web application framework that promotes rapid development and clean code. This guide will walk you through the steps to install Ruby on Rails using the Ruby Version Manager (RVM) on Arch Linux.

What You Will Need

Before you start, ensure you have:

  • An Arch Linux system up and running
  • A user account with sudo privileges
  • Basic knowledge of the terminal

Step 1: Update Your System

First things first, make sure your system is up to date. Open a terminal and run:

sudo pacman -Syu

This command updates your package lists and upgrades installed packages to the latest versions.

Step 2: Install Required Packages

Before installing RVM, you need to install some dependencies. In your terminal, execute the following command:

sudo pacman -Syu base-devel curl git
  • base-devel: Contains essential tools for building software.
  • curl: A command-line tool for transferring data with URLs, which you will need for downloading RVM.
  • git: A version control system to manage the code.

Step 3: Install RVM

Now it’s time to install RVM. RVM allows you to manage multiple Ruby environments and versions. Run the following commands:

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

This command fetches RVM from the official website and installs it. After installation, load RVM by running:

source ~/.rvm/scripts/rvm

To load RVM automatically each time you start a new terminal session, add the following line to your .bash_profile or .zshrc:

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

Note: If you’re using a different shell (like Zsh or Fish), the command may differ.

Step 4: Install Ruby

With RVM installed, you’re ready to install Ruby. You can check the available Ruby versions using:

rvm list known

Choose a version, then install it. For example, to install the latest stable version of Ruby, use:

rvm install ruby

After installation, set the newly installed Ruby version as the default:

rvm use ruby --default

You can verify your Ruby installation by checking the version:

ruby -v

Step 5: Install Rails

Now that Ruby is set up, it’s time to install Ruby on Rails. You can do that using the gem command, which manages Ruby libraries:

gem install rails

Once the installation is complete, confirm that Rails is installed properly by checking the version:

rails -v

Step 6: Install a Database

Ruby on Rails can work with various databases, but the most commonly used one is PostgreSQL. You can install PostgreSQL on Arch Linux with:

sudo pacman -S postgresql

After installation, initialize the database:

sudo -u postgres initdb --locale=$LANG -D '/var/lib/postgres/data'

Start and enable PostgreSQL service:

sudo systemctl start postgresql
sudo systemctl enable postgresql

To manage your Rails application’s database, you’ll also need to create a PostgreSQL user and database. You can do it by entering the PostgreSQL prompt with:

sudo -u postgres psql

Inside the PostgreSQL prompt, create a new role and database:

CREATE ROLE your_username WITH LOGIN PASSWORD 'your_password';
CREATE DATABASE your_database_name WITH OWNER your_username;

Don’t forget to exit PostgreSQL prompt with:

\q

Step 7: Create a New Rails Application

Now that everything is set up, let’s create a new Rails application. Replace your_app_name with the name of your application:

rails new your_app_name -d postgresql
cd your_app_name

Step 8: Configure Database Settings

Open the config/database.yml file in your newly created application and adjust the username and password to match the PostgreSQL user you created earlier.

development:
  adapter: postgresql
  encoding: unicode
  database: your_database_name
  pool: 5
  username: your_username
  password: your_password

Step 9: Create the Database

Run the following command to create the database:

rails db:create

Step 10: Start the Rails Server

You’re all set to start developing your Rails application! Launch the Rails server with:

rails server

Open your web browser and navigate to http://localhost:3000. You should see the Rails welcome page, indicating that your Ruby on Rails application is up and running.

Conclusion

Congratulations! You have successfully installed Ruby on Rails on Arch Linux using RVM. You can now start building your web applications with Ruby on Rails. Don’t hesitate to explore the extensive documentation available at Ruby on Rails Guides to dive deeper into the world of Rails development.