Skip to Content

How to Install Ruby and Rails: A Beginner’s Guide


Ruby on Rails, often referred to as Rails, is a popular web application framework built on the Ruby programming language. It’s known for its developer-friendly features, powerful tools, and simplicity. If you’re new to Rails, this guide will help you install Ruby and Rails from scratch, create your first Rails application, and see it running in your browser.


Step 1: Install Ruby

Ruby is the programming language that powers Rails. Before installing Rails, you need to install Ruby on your system.


What is Ruby?

Ruby is a dynamic, open-source programming language with a focus on simplicity and productivity. Rails is a framework built on Ruby, so you’ll need Ruby installed to use Rails.


Installation Instructions

For Windows:

  1. Download the RubyInstaller from rubyinstaller.org.
  2. Run the installer and follow the on-screen instructions:
    • Choose the recommended settings.
    • Ensure you check the option to add Ruby to your system PATH.
  3. After installation, open Command Prompt and verify the installation by running: This will display the Ruby version if installed correctly.
ruby -v


For macOS:

1. Open the Terminal.

2. Install Homebrew if it’s not already installed by running:

/bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

3. Use Homebrew to install Ruby:

brew install ruby

4. Verify the installation by running:

ruby -v


For Linux (Ubuntu):

1. Open your Terminal.

2. Update your package manager and install Ruby by running:

sudo apt update
sudo apt install ruby-full

3. Verify the installation by running:

ruby -v


Common Issues and Fixes

  • Command not found: Ensure Ruby is added to your system PATH.
  • For more help, visit the official Ruby documentation.


Step 2: Install Rails

Rails is distributed as a Ruby gem (a package of Ruby code). Installing Rails is straightforward once Ruby is set up.


Installation Command

Run the following command in your terminal or command prompt to install Rails:

gem install rails


Verify Installation

After the installation is complete, check the Rails version by running:

rails -v

You should see output like:

Rails 7.x.x


Step 3: Create Your First Rails Application

Now that Rails is installed, you’re ready to create your first Rails app.


Steps to Create a New App

1. Open your terminal or command prompt.

2. Run the following command to create a new Rails app named myapp:

rails new myapp

3. Navigate into the app directory by running:

cd myapp


What Happens During rails new?

The rails new command sets up the Rails framework, installs necessary dependencies, and creates a directory structure for your app. If prompted, allow Rails to install any additional required gems.


Step 4: Start the Rails Server

To see your app in action, you need to start the Rails server.


Steps to Start the Server

1. Ensure you are in the app directory (myapp).

2. Run the following command:

bin/rails server

Or simply:

rails server

3. By default, the server runs on port 3000.


Example Output

You’ll see output similar to this:

=> Booting Puma
=> Rails 7.x.x application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
...
Use Ctrl-C to stop


Step 5: View Your App in the Browser

1. Open your web browser.

2. Navigate to the following URL:

http://localhost:3000

3. You should see the default Rails welcome page with the message: “Yay! You’re on Rails!”


Congratulations! You’ve successfully set up and run your first Rails app.


Troubleshooting Common Issues

Issue: Missing Dependencies

  • Error: You need to install Node.js or Yarn.
  • Solution: Install Node.js and Yarn by running:
sudo apt install nodejs
sudo npm install --global yarn


Issue: Port Already in Use

  • Error: Address already in use - bind(2) for 127.0.0.1:3000.
  • Solution: Start the server on a different port:
rails server -p 3001


Issue: Permission Errors

  • Error: Permission denied.
  • Solution: Use sudo (Linux/macOS) or run your terminal as an administrator (Windows).


Conclusion

You’ve taken your first steps into the world of Ruby on Rails by installing Ruby and Rails, creating a new application, and running it in your browser. Rails makes it easy to build powerful web applications quickly, and this is just the beginning of your journey.

Explore Rails further by experimenting with controllers, models, and views. Happy coding!

Building a Chat App with Solid Cable: Simplifying Real-Time Communication