Install Heroku and PostgreSQL on macOS

Image for post
Image for post

Not natively available on macOS and not officially supported by Apple, your Mac machine might miss great web development functionalities such as Heroku and PostgreSQL. And it does require a bit of research to achieve a working station with Python3 (installed by default on macOS, but impossible to upgrade through Apple’s official support), pip (Python’s package manager), Django, PostgreSQL and Heroku CLI.

Install Python’s latest version package from the official website.

Install pip by downloading the installer and executing the script using Python:

python3 get-pip.py

Installing Herokus CLI on macOS is the easy step, just download and install the package for macOS from Heroku’s website.

Log in Heroku:

heroku login

Press any key except ‘q’ to login via your default browser.

Image for post
Image for post

You are logged in on Heroku CLI on macOS.

Models and migrations:
While Heroku migrates the database on site, the user has to make the model migrations locally, commit them to git before pushing the changes to the app.
Edit Profile and add the following at the top of the file:

On macOS the most simple to start and stop the PostgreSQL server when necessary is to install Postgres.app installation package.
Once done, the next step is to install the pyscopg2 module. Here, the easy way is to install yet again postgres with Homebrew.
Of course, you can do everything in the command line with only the postgres install from Homebrew and without Postgres.app, but it is easier to launch and stop the server from the status bar.

Install Homebrew, a package manager for macOS, packages not made available officially by Apple. Using following command, the script will explain what it will do and let you agree to continue.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Give Homebrew the rights to the /user/local folder:

sudo chown -R $(whoami) /usr/local

Update Homebrew:

brew update

Install PostgreSQL:

brew install postgresql

Now you can install psycopg2 without any issue:

pip3 install psycopg2

Launch Postgres.app, click on server settings:
Type localhost in name.

Double-click on any of the databases to open a terminal in order to create user and database:

CREATE USER name_of_user;
CREATE DATABASE name_of_db OWNER name_of_user;
ALTER USER name_of_user WITH PASSWORD ‘password’;

Considering your Django project uses a .env file to store sensitive configuration variables, edit your .env file and add the database url:

You can now migrate your models and apply those migrations on your local macOS machine:

python3 manage.py migrate
python3 manage.py makemigrations

Using programming for marketing and work efficiency

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store