user1709076 user1709076 - 5 months ago 138
Node.js Question

install canvas using npm on ubuntu 14

cant install canvas (after installing cairo) using npm on ubuntu 14.04 and doing:

sudo npm install canvas

I've already done:

sudo chown -R $(whoami) /usr/local/lib/node_modules


sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev

which all works fine.

I also tried just making the canvas/build directory but it doesnt matter and the directory disappears after running npm again

mkdir /home/ubuntu/server/node_modules/canvas/build

if it matters, I also had to soft link the command 'node', since ubuntu makes you type 'nodejs' instead of 'node' to run node

sudo ln -s /usr/bin/nodejs /usr/bin/node

also tried installing cairo manually (and that all works) but it doesnt matter, with -o cairo.tar.xz
tar -xzf cairo.tar.xz
cd cairo-1.14.10/
./configure --prefix=/usr/local --disable-dependency-tracking
sudo make
sudo make install

anyway here is the error i get after running:

sudo npm install canvas

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/ubuntu/server/node_modules/canvas/build'
gyp ERR! System Linux 3.13.0-116-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ubuntu/server/node_modules/canvas
gyp ERR! node -v v8.1.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN server No description
npm WARN server No repository field.
npm WARN server No license field.

npm ERR! errno 1
npm ERR! canvas@1.6.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the canvas@1.6.7 install script.

I have tried installing 'node-gyp' and i get nothing changing

sudo apt-get install node-gyp
Reading package lists... Done
Building dependency tree
Reading state information... Done
node-gyp is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 74 not upgraded.

i also tried running:

node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.13.0-116-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/ubuntu/server
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok

Answer Source

I have no solution for canvas and cairo on Ubuntu 14.04

The good news is i wiped my system and started with Ubuntu 16.04 and node 8 and 'it works' with the regular

sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++


sudo npm install

with package.json looking like

"dependencies": {
  "canvas": "~1",
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download