/ Tech

博客迁移至树莓派:记录

TL:DR:

node, npm, node-gyp 版本是大坑

本地编译有 error,必须加 --unsafe-perm 参数

最近重新折腾树莓派,打算把网站(基于 Ghost)也迁移到树莓派上放自己家里。系统是 Raspbian 最新版,但是坑巨多,在此记录。

Node

Ghost 新版本更新了蛮多,node 的推荐版本也变了。现在推荐的版本是 4.x LTS,显然 Raspian 仓库里没有。~~(这个仓库真的有人维护吗?)~~所以我们手动添加 NodeSource 源安装。

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

看看 node 版本:

apt-cache showpkg nodejs

我这是 4.8.2-1nodesource1~jessie1,手动指定安装

sudo apt-get install nodejs=4.8.2-1nodesource1~jessie1

Done.

npm

显然 npm 也太旧了,会出很多神奇的问题。为了避免这种情况也升级一下

sudo npm install -g npm

node-gyp

npm install -g node-gyp

不解释

However

~~当你做完上面所有的东西的时候,会发现这并没有什么卵用。~~按照官方教程的说法,执行 sudo npm install --production的时候,一个该死的 Error 永远会出现:

node-pre-gyp ERR! Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v3.1.8/node-v46-linux-arm.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for sqlite3@3.1.8 and node@4.8.2 (node-v46 ABI) (falling back to source compile with node-gyp) 
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/4.8.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/pi/ghost/node_modules/sqlite3/.node-gyp"
make: Entering directory '/home/pi/ghost/node_modules/sqlite3/build'
make: *** No rule to make target '../.node-gyp/4.8.2/include/node/common.gypi', needed by 'Makefile'。 停止。
make: Leaving directory '/home/pi/ghost/node_modules/sqlite3/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:285:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:12)
gyp ERR! System Linux 4.4.50-v7+
gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/pi/ghost/node_modules/sqlite3/lib/binding/node-v46-linux-arm/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/home/pi/ghost/node_modules/sqlite3/lib/binding/node-v46-linux-arm"
gyp ERR! cwd /home/pi/ghost/node_modules/sqlite3
gyp ERR! node -v v4.8.2
gyp ERR! node-gyp -v v3.6.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/nodejs /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/ghost/node_modules/sqlite3/lib/binding/node-v46-linux-arm/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/pi/ghost/node_modules/sqlite3/lib/binding/node-v46-linux-arm' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/pi/ghost/node_modules/sqlite3/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:862:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:222:5)
node-pre-gyp ERR! System Linux 4.4.50-v7+
node-pre-gyp ERR! command "/usr/bin/nodejs" "/home/pi/ghost/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/pi/ghost/node_modules/sqlite3
node-pre-gyp ERR! node -v v4.8.2
node-pre-gyp ERR! node-pre-gyp -v v0.6.31
node-pre-gyp ERR! not ok 
Failed to execute '/usr/bin/nodejs /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/pi/ghost/node_modules/sqlite3/lib/binding/node-v46-linux-arm/node_sqlite3.node --module_name=node_sqlite3 --module_path=/home/pi/ghost/node_modules/sqlite3/lib/binding/node-v46-linux-arm' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@3.1.8 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the sqlite3@3.1.8 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sqlite3 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sqlite3
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sqlite3
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-04-28T03_58_01_517Z-debug.log

最可怕的是,这坨 log 看起来很多,但是什么都没说。在寻找很久之后,在 GitHub 的一个小角落里找到了解决办法:

sudo npm install --unsafe-perm --production

问题解决,别的就和官方教程一样了。

于是从此以后,这个网站能不能打开就是缘分了。

BXIA

BXIA

Computer Science @ UofT. 这个博客纯属折腾,干货不存在的。

Read More