How to fix npm ERR! canvas@2.9.0 install: pkg-config: command not found in npm
This error occurs when installing node-canvas without the required system dependencies. Install Cairo and related graphics libraries for your Linux distribution to fix it.
Quick fix
Fixes npm ERR! canvas@2.9.0 install: pkg-config: command not found
sudo apt-get update
sudo apt-get install -y \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
pkg-config- Install dependencies on Ubuntu/Debian
- Install dependencies on CentOS/RHEL/Fedora
- Install dependencies on Alpine Linux
- Retry canvas installation
sudo apt-get updatesudo apt-get install -y \build-essential \libcairo2-dev \libpango1.0-dev \libjpeg-dev \libgif-dev \librsvg2-dev \pkg-confignpm ERR! canvas@2.9.0 install: pkg-config: command not found
What this error means
The node-canvas package is a Cairo-backed Canvas implementation for Node.js. It requires several native graphics libraries to be installed on your system before npm can build it. pkg-config is a helper tool that helps the build process find installed libraries. When it's missing, the compilation can't locate the required dependencies. This error commonly occurs on minimal server installations, Docker containers, or CI environments that don't include development libraries by default.
Typical symptoms
- npm install canvas fails with pkg-config not found
- Errors mentioning cairo, pango, or libjpeg during canvas install
- Installation works on development machines but fails on servers/CI
- Docker builds fail when adding canvas dependency
- node-gyp errors related to canvas compilation
Common causes
- pkg-config utility is not installed
- Cairo graphics library is missing
- Pango text rendering library is missing
- libjpeg, libpng, or giflib development headers missing
- Using minimal base image without development tools
How to fix "npm ERR! canvas@2.9.0 install: pkg-config: command not found"
Install all required packages:
sudo apt-get update
sudo apt-get install -y \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
pkg-configFor Red Hat-based systems:
sudo yum install -y \
gcc-c++ \
cairo-devel \
pango-devel \
libjpeg-turbo-devel \
giflib-devel \
librsvg2-devel \
pkgconfigOn Fedora, use dnf instead of yum.
For Alpine (common in Docker):
apk add --no-cache \
build-base \
g++ \
cairo-dev \
pango-dev \
jpeg-dev \
giflib-dev \
librsvg-dev \
pkgconfigAfter installing dependencies, install canvas:
npm install canvasOr rebuild if already in package.json:
npm rebuild canvasAdvanced notes
For Docker, add dependencies in your Dockerfile:
FROM node:20
# Install canvas dependencies
RUN apt-get update && apt-get install -y \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm ciFor multi-stage builds, remember that build dependencies are only needed in the build stage. The runtime stage needs the non-dev packages:
# Runtime stage only needs:
RUN apt-get update && apt-get install -y \
libcairo2 libpango-1.0-0 libjpeg62-turbo libgif7 librsvg2-2Consider using the canvas package's prebuilt binaries where available by checking their platform support documentation.
Frequently asked questions
- What does "npm ERR! canvas@2.9.0 install: pkg-config: command not found" mean?
- js. It requires several native graphics libraries to be installed on your system before npm can build it. pkg-config is a helper tool that helps the build process find installed libraries.
- How do I fix "npm ERR! canvas@2.9.0 install: pkg-config: command not found"?
- This error occurs when installing node-canvas without the required system dependencies. Install Cairo and related graphics libraries for your Linux distribution to fix it.
- What causes "npm ERR! canvas@2.9.0 install: pkg-config: command not found"?
- pkg-config utility is not installed Cairo graphics library is missing Pango text rendering library is missing
- Is the "npm ERR! canvas@2.9.0 install: pkg-config: command not found" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐Docs: canvas installation(Official Docs)
- ๐ฌSO: canvas pkg-config error(Stack Overflow)