Installation OSX

Ross Cairns edited this page Oct 5, 2016 · 34 revisions

There are several methods to install cairo on OSX, including mac ports, homebrew, and building from source. We will be installing from source, because this is what I prefer to do, as package managers are often out of date. These commands (or similar) are available on most systems, so these instructions will work on many other platforms as well.

The bulk of what you see here has been compiled into the ./install shell script in the node-canvas repo. Executing this will essentially execute what you see below.


Check for pkg-config via $ which pkg-config, if not found you will want to install it:

$ curl -o pkgconfig.tgz
$ tar -zxf pkgconfig.tgz && cd pkg-config-0.28
$ ./configure && make install

If you run into an error like the following:

configure: error: Either a previously installed pkg-config or "glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure to use the bundled copy.

run ./configure --with-internal-glib && make install

Installing Pixman

The first thing we need to do is install pixman, the pixel manipulation dependency of cairo.

$ curl -L -o pixman.tar.gz
$ tar -zxf pixman.tar.gz && cd pixman-0.30.0/
$ ./configure --prefix=/usr/local --disable-dependency-tracking
$ make install

If you encounter the following error:

pixman-mmx.c:100:20: error: constraint 'K' expects an integer constant
        : "y" (__A), "K" (__N)

Use release >=0.34.0 instead:

$ curl -L -o pixman.tar.gz
$ tar -zxf pixman.tar.gz && cd pixman-0.34.0/

Installing Cairo

Now we can install cairo itself in a similar manner:

$ curl -L -o cairo.tar.xz
$ tar -xf cairo.tar.xz && cd cairo-1.12.18
$ ./configure --prefix=/usr/local --disable-dependency-tracking
$ make install

A bug with cairo-1.14.2 can result in incorrect text sizing when rendering on OS X Yosemite.

If libpng fails and you get the error "error: recommended PNG functions feature could not be enabled", try installing this binary and re-running the configure step.

If you get the error "error: mandatory image surface backend feature could not be enabled", or "Package cairo was not found in the pkg-config search path.", the following command may resolve it:

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

If you see "Package 'xcb-shm', required by 'cairo', not found", you probably installed Cairo with homebrew and need to do this:

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig

Installing node-canvas

$ npm install canvas

or from source:

$ node-gyp rebuild

Having trouble with GIF or JPEGs?

If you're seeing either:

Error: error while reading from input stream


Error: Image given has not completed loaded

on OS X then you're probably missing giflib and/or libjpeg. Install it with homebrew via:

brew install giflib # for .gif files
brew install libjpeg # for .jpg files

Then recompile node-canvas.