Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Installation OSX

Kaanon MacFarlane edited this page · 25 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.

pkg-config

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

$ curl http://pkgconfig.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 http://www.cairographics.org/releases/pixman-0.22.0.tar.gz -o pixman.tar.gz
$ tar -zxf pixman.tar.gz && cd pixman-0.22.0/
$ ./configure --prefix=/usr/local --disable-dependency-tracking
$ make install

Installing Cairo

Now we can install cairo itself in a similar manner:

$ curl http://cairographics.org/releases/cairo-1.12.8.tar.xz -o cairo.tar.xz
$ tar -xf cairo.tar.xz && cd cairo-1.12.8
$ ./configure --prefix=/usr/local --disable-dependency-tracking
$ make install

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

or

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.

Something went wrong with that request. Please try again.