Zero to Running Rails on Fly.io in 15 minutes

By Justin 2024-05-21

NOTE: These steps are for a Mac (Sonoma 14.4.1). YMMV

It seems like every few months a reliable guide for "how to install X on Y" becomes out of date, or more often a dev will have to reference multiple guides to accomplish a single task.

Today's task: Create a Rails app locally & deploy it to Fly.io

These steps are an amalgamation of steps that I have in my brain combined with the standard Rails getting started guide as well as Fly.io's Rails setup guide.

Step 0 for me always, always, always should be to make sure a Ruby version manager is running and I'm ready to create a ruby version file (including gemset) in the soon-to-be-created Rails app's root folder. I have been using RVM for a very long time and I like it just fine. If you already have a solution that works for you, keep using it.

  1. Install RVM
  2. Activate the latest stable Ruby version and take note of the version number
    • For this guide I'm running Ruby 3.2.2
  3. Open up Terminal and navigate to wherever you create your Rails apps
  4. Create the new folder where your Rails app will live. For the sake of this guide let's say it's called: rails-sandbox
    • mkdir rails-sandbox
    • NOTE: I do this differently than most guides I've read. I prefer to have my RVM file in place first and foremost.
  5. Create your rvm+gemset file: echo "ruby-3.2.2@rails-sandbox" > rails-sandbox/.ruby-version
  6. Navigate into your nearly empty Rails directory and let RVM (or whatever you're using) do it's thing. The goal of this step is that by the time you're here the gems you install will be in a gemset specific to this new Rails app
  7. Install rails: gem install rails
  8. Create the rails app: rails new .
  9. Install Fly.io's CLI: brew install flyctl
  10. Configure and launch the app on Fly.io: fly launch
    • This will do lots of stuff and if you've never used Fly.io before, you'll be prompted to go into your browser and setup your Fly.io account, which includes choosing a plan and providing a credit card (I think?)
    • If you get stuck at this step let us know
  11. Deploy your app: fly deploy
    • This last command is what you'll use anytime you have updates you'd like to deploy

That's it! I was able to go from nothing to a local Hello World Rails app and finally to a Hello World Rails app running on Fly.io in about 15 minutes! Easy peasy

Getting the build pipeline running is WAY harder than this. I'm looking forward to nobuild!