Step by Step Guide To Deploying Your Project to Heroku

Selam Degefu
3 min readJun 25, 2021

If this is your first time deploying an app on Heroku, I will walk you through step-by-step guides on how to deploy your app and the potential errors you will run into. The first thing to make sure of is that your environment is set up. If you don’t have the right dependencies or version, you will run into several issues. Once you have your repo cloned and forked run bundle install. Let’s go over some potential issues you might run into when doing that. First error:

If you try to run the command gem install pg -v '1.2.3 it will give you an error that says:

Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.  Check the mkmf.log file for more details.  You may need configuration options.

This might mean several things. If your backend is built on Ruby then the latest Ruby release supported by Heroku is 2.7.3, and 3.0.1. You can check what version you have by running:

ruby -v 

If you have the version that is outdated or don’t have ruby installed yet you can install it by running:

rvm install 2.7.3
rvm --default use 2.7.3

If you do have the right ruby version then check to see if you have Java runtime in your environment. The newer macs don’t come with that pre-installed so you would need to do that. java -v will tell you if you have it or not. If you don’t then head to Oracle’s page and download the JDK.

Once you have that installed, delete the Gemfile.lock file and run bundle install again, this time it should work. After doing the install, run rails db:create so you can create your database. If you are using Postgresql, first make sure you have that installed. Use brew install postgresql to install it or check what version you have if you are not sure. If you get an error after installing Postgresql that says:

"An error occurred while installing pg (1.1.3), and Bundler cannot continue. Make sure that gem install pg -v '1.1.3' succeeds before bundling."

Then try running the command sudo apt install postgresql-contrib libpg-dev. You can read more about the error on this thread. Assuming you are able to get past this error, next run npm install —-prefix client(client is the name of my react folder so the folder path to your react app). Make sure to log in to your Heroku account first using heroku login . If you don’t have a Heroku account, you can make a free one here. Once you create your account log in using the CLI above then run heroku create my-app-name . Add the builds for Heroku to run the rails app on Ruby and build the React app on Node:

heroku buildpacks:add heroku/nodejs --index 1
heroku buildpacks:add heroku/ruby --index 2

If you don’t have NodeJS installed run nvm install node or else this will give you an error. To deploy your app after adding the builds, make sure to do:

git add .
git commit -m 'Commit message'
git push heroku main

That’s it, you have a live app deployed on Heroku. To open the app you can simply run the command heroku open . Happy coding :)

--

--