How to Install QGIS with Homebrew on macOS

This post explains how I installed the QGIS open source Geographical Information System software on macOS El Capitan using the Homebrew package manager. These are the results of my trial and error attempts to get QGIS installed and running smoothly without errors.

My successful installation of QGIS followed these steps:

  1. Install GDAL using Homebrew
  2. Install Python using Homebrew
  3. Install Python packages using Pip
  4. Install QGIS using Homebrew

Installing GDAL using Homebrew

QGIS requires the Geospatial Data Abstraction Library (GDAL) to be installed. I installed GDAL with Homebrew:

brew install gdal

Installing Python using Homebrew

QGIS requires the Python language and some Python packages to be installed. Although macOS has a version of Python, unfortunately it doesn’t come with the Pip package manager, which makes it easy to install Python packages.

I could have installed Pip using the easy_install tool that comes with the system Python, but this method requires using sudo. I’ve written previously about why using sudo to change the system version of Ruby is a bad idea and the same reasoning applies to changing the system version of Python. TL;DR - don’t do it.

The Homebrew version of Python comes with Pip so I installed Python using Homebrew:

brew install python

Installing Python with Homebrew gives us a version of Python that’s separate from the system Python, so any changes we make to the Homebrew version of Python won’t adversely affect macOS.

Installing Python Packages using Pip

QGIS requires matplotlib, the Python 2D plotting library, so I installed the matplotlib package with Pip:

pip install matplotlib

QGIS also requires psycopg2, which is a Python adapter for the PostgreSQL database, so I also installed the psycopg2 package with Pip:

pip install psycopg2

At this stage, Python was installed and ready to go with the packages required by QGIS.

Installing QGIS using Homebrew

I installed the Homebrew-osgeo4mac version of QGIS 2.8.9, which is the current stable long term release (LTR).

I began the installation by adding the osgeo/osgeo4mac GitHub repository to the list of sources for Homebrew packages (as per the instructions):

brew tap osgeo/osgeo4mac

Although the following command should install the Homebrew-osgeo4mac version of QGIS:

brew install qgis-28

it returned the following error:

Installing osgeo/osgeo4mac/qgis-28 dependency: gdal-grass64
Error: No available formula with the name "gdal-grass"
Searching for similarly named formulae...
This similarly named formula was found:
osgeo/osgeo4mac/gdal-grass64
To install it, run:
  brew install osgeo/osgeo4mac/gdal-grass64

Running the brew install osgeo/osgeo4mac/gdal-grass64 command just gave me the same error and the same suggested solution. Time to move on.

The installation was failing when attempting to install Grass, which is a set of tools for "geospatial data management and analysis, image processing, graphics and maps production, spatial modeling, and visualization." I felt I could live without Grass so I installed QGIS without it:

brew install qgis-28 --without-grass

This step succeeded and QGIS was finally installed. As a final step I issued the following command to make QGIS show up in the Applications folder:

brew linkapps qgis-28

Conclusion

These are the steps that worked for me to produce a clean and error free installation of QGIS 2.8.9 (LTR) using Homebrew. I hope they save you time if you want to install QGIS on macOS El Capitan using Homebrew.

blog comments powered by Disqus