0
0
RailsHow-ToBeginner · 3 min read

How to Run Rails Server in Ruby on Rails: Simple Steps

To run the Rails server, open your terminal, navigate to your Rails project folder, and type rails server or simply rails s. This command starts a local web server where you can view your app in a browser at http://localhost:3000.
📐

Syntax

The basic command to start the Rails server is rails server. You can shorten it to rails s for convenience. This command launches a local web server using default settings.

  • rails: The command-line tool for Ruby on Rails.
  • server or s: Tells Rails to start the web server.

You can add options like -p to specify a port or -b to bind to a specific IP address.

bash
rails server
# or
rails s
💻

Example

This example shows how to start the Rails server and access your app in a browser.

bash
$ cd my_rails_app
$ rails server
=> Booting Puma
=> Rails 7.0.4 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Version 5.6.4 (ruby 3.1.2-p20), codename: Birdie's Version
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop
Output
=> Booting Puma => Rails 7.0.4 application starting in development => Run `bin/rails server --help` for more startup options Puma starting in single mode... * Version 5.6.4 (ruby 3.1.2-p20), codename: Birdie's Version * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://127.0.0.1:3000 Use Ctrl-C to stop
⚠️

Common Pitfalls

Some common mistakes when running the Rails server include:

  • Running the command outside the Rails project folder, causing errors because Rails cannot find the app files.
  • Port 3000 already in use, which prevents the server from starting.
  • Not having required gems installed, leading to startup failures.

To fix these, always navigate to your project folder first, check for running servers on port 3000, or specify a different port with rails s -p 4000. Also, run bundle install to ensure all gems are installed.

bash
$ rails server
# Error: Could not find Rails application

# Correct way:
$ cd my_rails_app
$ rails server
📊

Quick Reference

CommandDescription
rails serverStarts the Rails web server on default port 3000
rails sShort form of rails server
rails s -p 4000Starts server on port 4000 instead of 3000
rails s -b 0.0.0.0Binds server to all IP addresses (useful for external access)
Ctrl-CStops the running Rails server

Key Takeaways

Run rails server inside your Rails project folder to start the local web server.
Access your app at http://localhost:3000 by default after starting the server.
Use rails s -p [port] to change the port if 3000 is busy.
Always ensure you are in the correct directory and have installed gems with bundle install.
Stop the server anytime with Ctrl-C in the terminal.