Rails Development

Setting Up My First Rails App (and the mistakes I made)

When I decided to learn Ruby on Rails, I thought the hardest part would be understanding MVC architecture or database relationships. I was wrong. The hardest part was just getting everything set up and running without breaking my computer.

If you're about to start your Rails journey, this post will save you hours of frustration by showing you the mistakes I made and how to avoid them.

The Wrong Way (What I Did First)

Like many beginners, I jumped straight into tutorials without properly setting up my development environment. Here's what went wrong:

Mistake #1: Using System Ruby

I started by installing Rails directly on my system Ruby. This seemed like the simplest approach:

# DON'T do this
sudo gem install rails

What went wrong: System Ruby is managed by your operating system and installing gems globally can cause conflicts. When I tried to work on different projects requiring different Ruby versions, everything broke.

Mistake #2: Skipping Database Setup

I ignored the database configuration, thinking Rails would "just work" with the default SQLite setup.

What went wrong: While SQLite works for development, I ran into issues when trying to deploy to production later. Many hosting platforms expect PostgreSQL, and switching databases mid-project is painful.

Mistake #3: Not Understanding the File Structure

I created my first Rails app and immediately felt overwhelmed by all the folders and files. I started randomly editing files without understanding what they did.

What went wrong: I broke my app multiple times and had to start over because I didn't understand the Rails conventions.

The Right Way (What I Should Have Done)

After several failed attempts and frustrating hours, here's the setup process that actually works:

Step 1: Install a Ruby Version Manager

Use rbenv (Mac/Linux) or RubyInstaller (Windows) to manage Ruby versions:

# On Mac (using Homebrew)
brew install rbenv ruby-build

# Add to your shell profile (~/.zshrc or ~/.bash_profile)
echo 'eval "$(rbenv init -)"' >> ~/.zshrc

# Install Ruby
rbenv install 3.1.0
rbenv global 3.1.0

# Verify installation
ruby -v

Why this matters: Different projects might need different Ruby versions. A version manager lets you switch between them easily without conflicts.

Step 2: Install Rails

With Ruby properly managed, install Rails:

gem install rails
rbenv rehash  # Important: updates rbenv's shims
rails -v     # Should show Rails version

Step 3: Set Up PostgreSQL

Even for development, use PostgreSQL to match your production environment:

# On Mac
brew install postgresql
brew services start postgresql

# On Ubuntu/Debian
sudo apt update
sudo apt install postgresql postgresql-contrib

# Create a database user (optional but recommended)
createuser --interactive --pwprompt

Step 4: Create Your First App Properly

# Create a new Rails app with PostgreSQL
rails new my_first_app --database=postgresql
cd my_first_app

# Install dependencies
bundle install

# Set up the database
rails db:create

Understanding What Rails Created

When you run rails new, Rails generates a lot of files. Here's what the important ones do:

my_first_app/
├── app/                 # Your application code
│   ├── controllers/     # Handle web requests
│   ├── models/         # Database interactions
│   ├── views/          # HTML templates
│   └── helpers/        # View helper methods
├── config/             # App configuration
│   ├── routes.rb       # URL routing
│   └── database.yml    # Database settings
├── db/                 # Database files
│   └── migrate/        # Database changes
├── Gemfile             # Ruby dependencies
└── README.md           # Project documentation

Pro tip: Don't try to understand everything at once. Focus on the app/ folder first—that's where you'll spend most of your time.

Your First "Hello World"

Let's create something that actually works:

  1. Generate a controller:
    bash
    rails generate controller Pages home

  2. Update the route in config/routes.rb:
    ruby
    Rails.application.routes.draw do
    root 'pages#home'
    get 'pages/home'
    end

  3. Edit the view in app/views/pages/home.html.erb:
    erb
    <h1>Hello, Rails World!</h1>
    <p>My first Rails app is working!</p>
    <p>Current time: <%= Time.current %></p>

  4. Start the server:
    bash
    rails server

  5. Visit http://localhost:3000 and see your app running!

Common Setup Issues (And Solutions)

"Bundle install fails"

# Solution: Make sure you have the right dependencies
# On Mac:
brew install libpq  # for PostgreSQL

# On Ubuntu:
sudo apt-get install libpq-dev

"Rails server won't start"

# Check if the port is already in use
lsof -i :3000

# Kill the process if needed
kill -9 [PID]

# Or use a different port
rails server -p 3001

"Database connection fails"

Make sure PostgreSQL is running:
```bash

Mac

brew services start postgresql

Ubuntu

sudo systemctl start postgresql
```

Development Tools That Actually Help

After making these mistakes, I discovered some tools that make Rails development much smoother:

1. VS Code Extensions

  • Ruby by Peng Lv - Syntax highlighting and debugging
  • Rails by Hridoy - Rails-specific features
  • ERB Helper Tags - Makes ERB templates easier to work with

2. Terminal Setup

# Add these aliases to your shell profile
alias rs="rails server"
alias rc="rails console"
alias rg="rails generate"
alias rdb="rails db:migrate"

3. Git Setup

Initialize Git right away:
bash
git init
git add .
git commit -m "Initial Rails setup"

What I Wish I'd Known Earlier

  1. Read the error messages carefully - Rails error messages are usually helpful, but I was too intimidated to read them at first.

  2. The Rails console is your friend - Use rails console to test code snippets and explore your app:
    ```bash
    rails console

    Try things like:

    User.all

    User.new(name: "Test")

  3. Generators save time - Instead of creating files manually, use Rails generators:
    bash
    rails generate model User name:string email:string
    rails generate controller Users index show new create

  4. The Rails guides are gold - When you're stuck, check the official Rails guides. They're written for beginners.

Next Steps

Now that you have a working Rails environment:

  1. Follow a complete tutorial - I recommend the Rails Tutorial by Michael Hartl
  2. Build something simple - A todo list, blog, or personal inventory
  3. Join the community - Rails communities are welcoming to beginners

Wrapping Up

Setting up Rails doesn't have to be frustrating if you follow the right steps. The key lessons I learned:

  • Use a Ruby version manager from the start
  • Set up PostgreSQL early
  • Don't be afraid of the file structure
  • Use the tools Rails provides (console, generators, guides)

Remember: every Rails developer has been where you are now. The setup pain is temporary, but the productivity gains from Rails last throughout your development journey.

Have you run into other setup issues? Let me know in the comments, and I'll help you troubleshoot!


What's next: In my next post, I'll dive into understanding Rails routes and why they're the foundation of every Rails app.

Christopher Lim

Christopher Lim

Rails developer and Unity explorer. Family man, lifelong learner, and builder turning ideas into polished applications. Passionate about quality software development and continuous improvement.

Back to All Posts
Reading time: 6 min read

Enjoyed this rails development post?

Follow me for more insights on rails development, Rails development, and software engineering excellence.