Skip to content

Installation: Mac OS X

Mike Horn edited this page Jun 19, 2019 · 5 revisions

There are several methods to install cairo on OSX, including MacPorts, Homebrew, and building all dependencies from source.

Homebrew

brew install pkg-config cairo pango libpng jpeg giflib librsvg

Note: jpeg, giflib and librsvg are optional dependencies required for JPEG, GIF and SVG image support only.

MacPorts

port install pkgconfig cairo pango libpng jpeg giflib librsvg

Note: jpeg, giflib and librsvg are optional dependencies required for JPEG, GIF and SVG image support only.

From source

pkg-config

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

$ curl https://pkg-config.freedesktop.org/releases/pkg-config-0.28.tar.gz -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 http://www.cairographics.org/releases/pixman-0.30.0.tar.gz -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
      expression
        : "y" (__A), "K" (__N)

Use release >=0.34.0 instead:

$ curl -L http://www.cairographics.org/releases/pixman-0.34.0.tar.gz -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 http://www.cairographics.org/releases/cairo-1.12.18.tar.xz -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 one of these errors:

Error: error while reading from input stream
Error: Image given has not completed loaded
Error: node-canvas was built without GIF support

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.