PRO 30% Free • Stripe ($15) & Razorpay (₹899)

Deploy Rails to Heroku

Top Course Staff · 2 min read · Web development · PRO · 30% Free Preview Available

Deploy Rails to Heroku

Background

After developing aRailsapp locally, the next step is to put it online. After developing a Rails app and previewing it locally on your computer, the next step is to put it online so others can see it. This is called deploying your app.

Herokuis a popular hosting service that is free to start using. Here’s how to deploy your Rails app to Heroku.

Instructions

  • Create anew Heroku account.
  • Install theHeroku Toolbelton your computer.
  • In the terminal, log in using the email address and password you used when creating your Heroku account:$ heroku loginCopy to clipboard
  • InGemfile, add thepggem to your Rails project. Change:gem sqliteCopy to clipboardtogem'sqlite3',group::developmentgem'pg','0.18.1',group::productionCopy to clipboard
  • InGemfile, add therails_12factorgem::gem'rails_12factor',group::productionCopy to clipboard
  • In the terminal, install the gems specified in theGemfile:$ bundle installCopy to clipboard
  • Ensureconfig/database.ymlis using thepostgresqladapter. Change:production: <<: *default database: db/production.sqlite3toproduction: <<: *default adapter: postgresql database: db/production.sqlite3
  • Commit your changes to git:$ git add .$ git commit -m "Heroku config"Copy to clipboard
  • In the terminal, create an app on Heroku:$ heroku createCopy to clipboard
  • Push your code to Heroku on themainbranch:$ git push heroku mainCopy to clipboard
$ heroku login
Copy to clipboard
$ heroku login
gem sqlite
Copy to clipboard
gem sqlite
gem 'sqlite3', group: :developmentgem 'pg', '0.18.1', group: :production
Copy to clipboard
gem 'sqlite3', group: :developmentgem 'pg', '0.18.1', group: :production
gem 'rails_12factor', group: :production
Copy to clipboard
gem 'rails_12factor', group: :production
$ bundle install
Copy to clipboard
$ bundle install
production:
  <<: *default
  database: db/production.sqlite3
production:
  <<: *default
  adapter: postgresql
  database: db/production.sqlite3
$ git add .$ git commit -m "Heroku config"
Copy to clipboard
$ git add .$ git commit -m "Heroku config"
$ heroku create
Copy to clipboard
$ heroku create
$ git push heroku main
Copy to clipboard
$ git push heroku main

Note: If you’re unable to push your code, you may have skipped a step or have a differently named branch. 11. If you are using the database in your application, migrate the database by running:bash $ heroku run rake db:migrate12. If you need to seed your database with data, run:bash $ heroku run rake db:seed13. Get the URL of your app and visit it in the browser:bash $ heroku apps:infoIn the output, copy the address in theWeb URLfield. Open a new tab in your browser, and visit your app.

Check outHeroku’s Rails docsfor more information.

'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'

30% Free Preview Reached · Unlock Remaining 70%

Complete Payment to Unlock Full Guide & Source Code

You are viewing the 30% preview. Join TopCourseAI Pro to unlock the remaining 70% of this article, unblur all code snippets, and gain full access to all 412 technical projects and guides.

✓ Full Access to All 160+ Projects
✓ Instant Blur Removal Everywhere
✓ Production Source Code & Blueprints
✓ All Future Deep Dives Included
Instant Unhindered Activation ·
End of Preview · Unlock Complete Blueprint & Source Code

Ready to access the complete step-by-step tutorial?

Gain full unhindered access to all 412 technical projects and guides, unblur all source code snippets, and download runnable scripts.

Production AI Blueprints

Ready to build production-grade AI systems?

Enjoyed this guide? Continue exploring our library of 166+ production blueprints, multi-agent swarms, and autonomous agent systems with 100% unblurred, executable source code.