Deploy Rails to Heroku
Background
After developing a Rails app 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.
Heroku is a popular hosting service that is free to start using. Here’s how to deploy your Rails app to Heroku.
Instructions
Create a new Heroku account.
Install the Heroku Toolbelt on your computer.
In the terminal, log in using the email address and password you used when creating your Heroku account:
$ heroku loginIn Gemfile, add the
pggem to your Rails project. Change:gem sqliteto
gem 'sqlite3', group: :developmentgem 'pg', '0.18.1', group: :productionIn Gemfile, add the
rails_12factorgem::gem 'rails_12factor', group: :productionIn the terminal, install the gems specified in the Gemfile:
$ bundle installEnsure config/database.yml is using the
postgresqladapter. Change:production: <<: *default database: db/production.sqlite3to
production: <<: *default adapter: postgresql database: db/production.sqlite3Commit your changes to git:
$ git add .$ git commit -m "Heroku config"In the terminal, create an app on Heroku:
$ heroku createPush your code to Heroku on the
mainbranch:$ 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 out Heroku’s Rails docs for 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.'
Meet the full teamRelated articles
- Article
Deploying a Flask App
Learn how to deploy your own Flask application with Heroku. - Article
Going Beyond with Heroku
With Heroku being "the fastest way to go from idea to URL", deploying an app is a fairly simple process. But there are many more features that make Heroku a solid choice when it comes to configuring, scaling, tuning, and managing apps. - Article
Deploying a Back-End with Heroku
Learn how to deploy a back-end app using Heroku and GitHub.
Learn more on Codecademy
- Make the deployment process easier by using Heroku's services so you can quickly share web app with the world!
- With Certificate
- Beginner Friendly.< 1 hour
- Learn the basics of building applications with this convenient and powerful web development framework.
- With Certificate
- Intermediate.6 hours
- In this course, you will learn how to improve your own programming process by writing bash scripts that save you precious time.
- With Certificate
- Intermediate.1 hour