在ubuntu 14上使用npm安装canvas

时间:2017-09-19 03:34:21

标签: node.js canvas ubuntu-14.04 npm-install cairo

无法在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目录但是没关系,再次运行npm后目录就消失了

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

如果重要,我还必须软连接命令'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

无论如何,这是我跑完后得到的错误:

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 

1 个答案:

答案 0 :(得分:2)

我在Ubuntu 14.04上没有canvas和cairo的解决方案

好消息是我擦拭了我的系统并开始使用Ubuntu 16.04和节点8,它的工作原理是'与常规

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

sudo npm install

使用package.json看起来像

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