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 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.
./configure --with-internal-glib && make install
The first thing we need to do is install pixman, the pixel manipulation dependency of cairo.
$ curl 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
Now we can install cairo itself in a similar manner:
$ curl http://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 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
$ npm install canvas
or from source:
$ node-gyp rebuild
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.