Ruby on Rails Local Development Guide

Run Ruby web applications on localhost:3000 using Rails, with built-in Puma server and Active Record.


Ruby on Rails is a classic full-stack web framework that emphasizes convention over configuration. For local development, it uses Puma, with the default address being http://localhost:3000.

Quick Start

rails new myapp
cd myapp
bin/rails server
# or bin/dev (Rails 7+ includes JS/CSS build)

Open your browser and navigate to http://localhost:3000.

Specify Port

bin/rails server -p 3001

Database

The default database for the development environment is SQLite (db/development.sqlite3), requiring no additional services.

To use PostgreSQL:

# config/database.yml
development:
  adapter: postgresql
  host: localhost
  port: 5432
  database: myapp_development
bin/rails db:create db:migrate

Common Commands

bin/rails console      # REPL
bin/rails routes       # Route table
bin/rails db:migrate

config.hosts typically allows localhost in the development environment; if accessing via a custom domain (like lvh.me), you need to permit it in development.rb.

Frequently Asked Questions

Port 3000 Occupied
Change -p or terminate other Node/Rails processes.

Bundler gem Installation Failed
Ensure the Ruby version matches the one in the Gemfile; run bundle install.

Summary

To run Rails locally, execute bin/rails server and access http://localhost:3000. SQLite requires zero configuration to get started.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run