Ruby on Rails getting started: install, create, and run your first app
Ruby on Rails is a powerful web framework that lets you build full-stack applications quickly. It follows the convention over configuration principle, which means Rails makes intelligent assumptions about how your application should be structured. This tutorial walks you through installing Rails, creating your first app, and understanding the pieces you will use most often.
Intro context
Getting started with Rails is mostly about learning the shape of the framework. Once you understand where configuration lives, how routes connect to controller actions, and how the application directory is organised, the rest of the stack starts to feel familiar.
That is why this guide starts with the smallest possible Rails app instead of jumping straight into models or forms. If you can install Rails, create an app, and run the server, you already have the basic feedback loop you need for everything else in the series.
TL;DR
- Install Rails after you confirm Ruby is already available.
- Use
rails newto create a fresh application skeleton. - Learn the common directories in
app/,config/, anddb/. - Create a controller and a route to make the app respond to a browser request.
- Run
rails serverto see the application in action locally.
What is Ruby on Rails?
Rails is a server-side web application framework written in Ruby. It was created in 2004 and has since become one of the most popular frameworks for building web applications. Companies like GitHub, Shopify, and Airbnb all use Rails in production.
Rails emphasises two key philosophies:
- Convention over Configuration: Rails provides sensible defaults and conventions that reduce the amount of code you need to write. Instead of configuring every aspect of your application, you follow Rails conventions and let the framework handle the rest.
- Don’t Repeat Yourself (DRY): Rails encourages code reuse and modularity. Write something once, and you can use it everywhere.
That combination is why Rails feels productive so quickly. You spend less time wiring up infrastructure and more time describing the parts of the application that are actually specific to your project.
Installing Rails
Before installing Rails, make sure you have Ruby installed on your system. You can check by running:
ruby --version
If Ruby is installed, you’ll see output like ruby 3.4.x. Now install Rails using the gem command:
This installs the latest stable version of Rails. To verify the installation succeeded, check the version number. If the version command fails, fix the Ruby installation first because Rails sits on top of Ruby and the framework depends on a healthy Ruby environment before anything else can work.
gem install rails
This installs the latest stable version of Rails. To verify the installation:
The creation process takes a minute or two. Once complete, navigate into the new application directory. At this point you have a real Rails project, not just a gem install. The framework has already created the initial files, directories, and configuration entry points you will build on in the rest of the guide.
rails --version
You should see something like Rails 8.0.x.
If the version command fails, fix the Ruby installation first. Rails sits on top of Ruby, so the framework depends on a healthy Ruby environment before anything else can work.
Creating your first Rails application
Now let’s create a new Rails application. Open your terminal and run:
rails new my_first_app
This command creates a new Rails project called my_first_app in a directory of the same name. Rails will automatically create the directory structure, install necessary dependencies, set up the database configuration, and generate essential files.
The creation process takes a minute or two. Once complete, navigate into your new application:
cd my_first_app
At this point you have a real Rails project, not just a gem install. That means the framework has already created the initial files, directories, and configuration entry points you will build on in the rest of the guide.
Understanding the directory structure
A newly created Rails application has a well-organised directory structure. Here’s what each folder does:
| Directory | Purpose |
|---|---|
app/ | Contains your application code (controllers, models, views) |
config/ | Configuration files for your application |
db/ | Database migrations and schema files |
public/ | Static files (images, CSS, JavaScript) |
test/ | Test files for your application |
config/routes.rb | Defines your application’s URLs |
The most important directories are inside app/:
app/controllers/- Handles HTTP requests and responsesapp/models/- Represents your data and business logicapp/views/- Templates that get rendered to usersapp/assets/- Stylesheets and JavaScript files
Spend a little time here if you are new to Rails. Knowing where controllers, models, and views live will save you a lot of confusion later, because most Rails instructions assume you already recognise those folders.
Creating your first route and controller
Let’s create a simple page to see Rails in action. First, generate a controller:
rails generate controller Home index
This creates a HomeController with an index action. It also creates a view file at app/views/home/index.html.erb.
Now open config/routes.rb and add a root route:
This tiny routing change is the heart of the Rails request cycle. A browser sends a request, the router picks a controller action, and the controller chooses the response. Once that flow is clear, the rest of Rails starts to make sense because every feature builds on this same pattern of route-to-controller-to-response.
Rails.application.routes.draw do
root "home#index"
end
This tells Rails to route the homepage URL (/) to the index action of the HomeController.
That tiny routing change is the heart of the Rails request cycle. A browser sends a request, the router picks a controller action, and the controller chooses the response. Once that flow is clear, the rest of Rails starts to make sense.
Starting the Rails server
Start the development server:
rails server
Or the shorter version:
The server binds to port 3000 by default on your local machine. Open a browser and navigate to that address to see either the default Rails welcome page or the content from your controller action. If you see anything other than an error, you have successfully created and run your first Rails application.
rails s
You should see output indicating the server is running, typically on http://localhost:3000. Open your web browser and navigate to that URL. You should see the default Rails welcome page or the content from your HomeController#index action.
Congratulations! You’ve created and run your first Rails application.
Frequently asked questions
What should I learn next?
The next logical step is the MVC pattern, because it explains how Rails separates application responsibilities into models, views, and controllers.
Do I need a database right away?
Not for the first steps. You can create and run a basic Rails app before you add tables or models, which makes the first setup much less intimidating.
Why does Rails feel opinionated?
Rails uses conventions so it can guess the right file names, folder structure, and request flow for you. That keeps the setup small and makes most tutorials easier to follow.
Next steps
Now that you have a working Rails application, continue with the next tutorial in this series to learn about the MVC pattern in Rails. Understanding MVC is fundamental to building Rails applications effectively. The next tutorial covers how Rails organises code using Models, Views, and Controllers, and why this separation of concerns makes your applications maintainable.
See Also
- Rails routing - learn how requests reach controller actions
- Rails MVC pattern - the next tutorial in the series
- Rails official guides - primary framework documentation