在 ubuntu 14 上使用 npm 安装 canvas

install canvas using npm on ubuntu 14

无法在 ubuntu 14.04 上使用 npm 安装 canvas(在安装 cairo 之后)并执行:

sudo npm install canvas

我已经完成了:

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

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

一切正常。

我也试过只创建 canvas/build 目录,但这没关系,目录在再次 运行ning npm 后消失了

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

如果重要的话,我还必须软化 link 命令 'node',因为 ubuntu 让你键入 'nodejs' 而不是 'node' 到 运行节点

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

也尝试过手动安装 cairo(一切正常),但没关系,

https://www.cairographics.org/releases/cairo-1.14.10.tar.xz -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

无论如何这是我在 运行ning:

之后得到的错误
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! code ELIFECYCLE
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.

我已经尝试安装 'node-gyp' 但我没有任何改变

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.

我也试过 运行宁:

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 

我在 Ubuntu 14.04

上没有 canvas 和 cairo 的解决方案

好消息是我擦除我的系统并开始使用 Ubuntu 16.04 和节点 8 以及 'it works' 和常规

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

sudo npm 安装

与 package.json 看起来像

{
"dependencies": {
  "canvas": "~1",
  }
 }