BeagleBone BlackにNode.jsをインストールする(セルフビルド)

いつものようにNode.jsをインストールします。今回はnvmではなくnodebrewを使い、セルフビルドにてインストールします。

BeagleBone Black用のNode.js

ビルドするのが面倒な方はこちらにインストールバイナリがありますので、こちらを使ったほうが楽チンです。その場合はnodebrewは必要ありません。このリンク先のNode.jsのバージョンはv0.10.21なので、同じバージョンをnodebrewでセルフビルドでインストールします

ビルド環境のインストール

ubuntu@ubuntu-armhf:~$ sudo apt-get install curl build-essential libssl-dev

nodebrewのインストール

nodebrewに関してはBlock Rockin’ Codesに記事があるのでご参考に。nodebrewのサイトはこちらです。サイトにあるように下記コマンドでインストールできます。なおnodebrewをインストールするとnpm(Node Package Manager)も同時にインストールされます。

ubuntu@ubuntu-armhf:~$ curl -L git.io/nodebrew | perl - setup
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 18651  100 18651    0     0  18947      0 --:--:-- --:--:-- --:--:-- 18947
fetching nodebrew...
install nodebrew in $HOME/.nodebrew

========================================
Add path:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================

インストールしたら、上記パスをvimなどで.bashrcに追加して、sourceコマンドで読み込みなおしておきます

ubuntu@ubuntu-armhf:~$ vim .bashrc
ubuntu@ubuntu-armhf:~$ source .bashrc 

nodebrew ls-remoteで使えるNode.jsのバージョンが取得できます

ubuntu@ubuntu-armhf:~$ nodebrew ls-remote
-- 省略--
v0.9.0    v0.9.1    v0.9.2    v0.9.3    v0.9.4    v0.9.5    v0.9.6    v0.9.7
v0.9.8    v0.9.9    v0.9.10   v0.9.11   v0.9.12   

v0.10.0   v0.10.1   v0.10.2   v0.10.3   v0.10.4   v0.10.5   v0.10.6   v0.10.7
v0.10.8   v0.10.9   v0.10.10  v0.10.11  v0.10.12  v0.10.13  v0.10.14  v0.10.15
v0.10.16  v0.10.17  v0.10.18  v0.10.19  v0.10.20  v0.10.21  v0.10.22  v0.10.23


v0.11.0   v0.11.1   v0.11.2   v0.11.3   v0.11.4   v0.11.5   v0.11.6   v0.11.7
v0.11.8   v0.11.9   

nodebrewにはバイナリのインストール機能がありますので、試しにv0.10.21をインストールしようとすると、サポートしてないよ!ってエラーが出てしまいます。

ubuntu@ubuntu-armhf:~$ nodebrew install-binary v0.10.21
Error: Linux armv7l is not supported. at /home/ubuntu/.nodebrew/current/bin/nodebrew line 585.

Node.jsのセルフビルドでのインストール

というわけで、セルフビルドでインストールします (ちなみに以下、失敗します...ちゃんと動くようにビルドするにはコチラへ)

ubuntu@ubuntu-armhf:~$ nodebrew install v0.10.21

セルフビルドは約1時間・・・(class2のSDカードだったのでclass10だともっと速いと思われ)

installing /home/ubuntu/.nodebrew/node/v0.10.21/lib/node_modules/npm/lib/utils/completion/installed-shallow.js
installing /home/ubuntu/.nodebrew/node/v0.10.21/lib/node_modules/npm/lib/utils/completion/file-completion.js
symlinking ../lib/node_modules/npm/bin/npm-cli.js -> /home/ubuntu/.nodebrew/node/v0.10.21/bin/npm
updating shebang of /home/ubuntu/.nodebrew/node/v0.10.21/bin/npm to /home/ubuntu/.nodebrew/node/v0.10.21/bin/node

ちゃんとインストールされたか確認

ubuntu@ubuntu-armhf:~$ nodebrew ls
v0.10.21

current: none

v0.10.21を使用するように指定

ubuntu@ubuntu-armhf:~$ nodebrew use v0.10.21
use v0.10.21
ubuntu@ubuntu-armhf:~$ 

さて、ではnodeを起動してみます

ubuntu@ubuntu-armhf:~$ node 
Segmentation fault

_人人人人人人人人人人人_
> Segmentation fault <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄

...orz

続く

BeagleBone BlackにNode.jsをインストールする2(セルフビルド)

前回のおさらい

見事にビルドに失敗・・・ググってみたら、傘のお肉はどこにあるの?知り合いの@iwata_nのブログに引っ掛かったw

つまりは

./configure --without-snapshot

が必要ということなので、nodebrewのソースを修正して対応します。

nodebrew本体のコード(~./nodebrew/nodebrew)の「sub _cmd_install」にあるConfigureに--without-snapshotを追加します

system qq[
    cd "$src_dir/$target_name" &&
    ./configure --without-snapshot --prefix="$self->{node_dir}/$version" &&
    make &&
    make install
];

これでもう一度インストールしてみます。一旦さっきのバージョンをuninstallしておいてから再度インストール。

ubuntu@ubuntu-armhf:~$ nodebrew uninstall v0.10.21
v0.10.21 uninstalled
ubuntu@ubuntu-armhf:~$ nodebrew ls
not installed

current: none
ubuntu@ubuntu-armhf:~$ nodebrew install v0.10.21
fetch: http://nodejs.org/dist/v0.10.21/node-v0.10.21.tar.gz
######################################################################## 100.0%
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'arm_fpu': 'vfpv3',
                 'arm_neon': 0,
                 'armv7': 1,
                 'clang': 0,
                 'gcc_version': 46,
                 'host_arch': 'arm',
                 'node_install_npm': 'true',
                 'node_prefix': '/home/ubuntu/.nodebrew/node/v0.10.21',
                 'node_shared_cares': 'false',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_v8': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_unsafe_optimizations': 0,
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'false',
                 'node_use_systemtap': 'false',
                 'python': '/usr/bin/python',
                 'target_arch': 'arm',
                 'v8_enable_gdbjit': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_use_arm_eabi_hardfloat': 'true',
                 'v8_use_snapshot': 'false'}}

「'v8_use_snapshot': 'false'」になっています。失敗した時のログを見てみると

fetch: http://nodejs.org/dist/v0.10.21/node-v0.10.21.tar.gz
######################################################################## 100.0%
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'arm_fpu': 'vfpv3',
                 'arm_neon': 0,
                 'armv7': 1,
                 'clang': 0,
                 'gcc_version': 46,
                 'host_arch': 'arm',
                 'node_install_npm': 'true',
                 'node_prefix': '/home/ubuntu/.nodebrew/node/v0.10.21',
                 'node_shared_cares': 'false',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_v8': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_unsafe_optimizations': 0,
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'false',
                 'node_use_systemtap': 'false',
                 'python': '/usr/bin/python',
                 'target_arch': 'arm',
                 'v8_enable_gdbjit': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_use_arm_eabi_hardfloat': 'true',
                 'v8_use_snapshot': 'true'}}

こちらはtrueになっていました。

さてまたしても1時間経過・・・ビルド完了

symlinking ../lib/node_modules/npm/bin/npm-cli.js -> /home/ubuntu/.nodebrew/node/v0.10.21/bin/npm
updating shebang of /home/ubuntu/.nodebrew/node/v0.10.21/bin/npm to /home/ubuntu/.nodebrew/node/v0.10.21/bin/node
ubuntu@ubuntu-armhf:~$ nodebrew ls
v0.10.21

current: none
ubuntu@ubuntu-armhf:~$ nodebrew use v0.10.21
use v0.10.21
ubuntu@ubuntu-armhf:~$ node
>

というわけで、無事Node.jsが起動できるようになりました。

BeagleBone BlackのAngstrom Linuxに入ってるNode.jsについて

ちょっとだけ調べてみました。

Nodeのバージョン

root@beaglebone:~# node -v
v0.8.22

Node Package Managerも入っているようです

root@beaglebone:~# npm

Usage: npm <command>

where <command> is one of:
    add-user, adduser, apihelp, author, bin, bugs, c, cache,
    completion, config, ddp, dedupe, deprecate, docs, edit,
    explore, faq, find, find-dupes, get, help, help-search,
    home, i, info, init, install, isntall, issues, la, link,
    list, ll, ln, login, ls, outdated, owner, pack, prefix,
    prune, publish, r, rb, rebuild, remove, restart, rm, root,
    run-script, s, se, search, set, show, shrinkwrap, star,
    stars, start, stop, submodule, tag, test, tst, un,
    uninstall, unlink, unpublish, unstar, up, update, version,
    view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    /home/root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@1.2.14 /usr/lib/node_modules/npm

Nodeのパッケージを調べてみる

root@beaglebone:~# npm list -g
/usr/lib
├─┬ bonescript@0.2.2
│ ├─┬ express@3.1.0
│ │ ├── buffer-crc32@0.1.1
│ │ ├── commander@0.6.1
│ │ ├─┬ connect@2.7.2
│ │ │ ├── bytes@0.1.0
│ │ │ ├── formidable@1.0.11
│ │ │ ├── pause@0.0.1
│ │ │ └── qs@0.5.1
│ │ ├── cookie@0.0.5
│ │ ├── cookie-signature@0.0.1
│ │ ├── debug@0.7.2
│ │ ├── fresh@0.1.0
│ │ ├── methods@0.0.1
│ │ ├── mkdirp@0.3.3
│ │ ├── range-parser@0.0.4
│ │ └─┬ send@0.1.0
│ │   └── mime@1.2.6
│ ├── UNMET DEPENDENCY serialport 0.7.5
│ ├─┬ socket.io@0.8.7
│ │ ├── policyfile@0.0.4
│ │ ├── redis@0.6.7
│ │ └─┬ socket.io-client@0.8.7
│ │   ├── uglify-js@1.0.6
│ │   ├── websocket-client@1.0.0
│ │   └── xmlhttprequest@1.2.2
│ ├── systemd@0.2.0
│ └─┬ winston@0.6.2
│   ├── async@0.1.22
│   ├── colors@0.6.0-1
│   ├── cycle@1.0.2
│   ├── eyes@0.1.8
│   ├── pkginfo@0.2.3
│   ├── request@2.9.203
│   └── stack-trace@0.0.6
└─┬ npm@1.2.14
  ├── abbrev@1.0.4
  ├── ansi@0.1.2
  ├── archy@0.0.2
  ├── block-stream@0.0.6
  ├── chmodr@0.1.0
  ├── chownr@0.0.1
  ├── fstream@0.1.22
  ├─┬ fstream-npm@0.1.3
  │ └── fstream-ignore@0.0.6
  ├── glob@3.1.21
  ├── graceful-fs@1.2.0
  ├── inherits@1.0.0
  ├── ini@1.1.0
  ├─┬ init-package-json@0.0.6
  │ └── promzard@0.2.0
  ├── lockfile@0.3.0
  ├── lru-cache@2.2.2
  ├─┬ minimatch@0.2.11
  │ └── sigmund@1.0.0
  ├── mkdirp@0.3.5
  ├── node-gyp@0.8.5
  ├── nopt@2.1.1
  ├─┬ npm-registry-client@0.2.18
  │ └── couch-login@0.1.15
  ├─┬ npmconf@0.0.23
  │ └─┬ config-chain@1.1.5
  │   └── proto-list@1.2.2
  ├── npmlog@0.0.2
  ├── once@1.1.1
  ├── opener@1.3.0
  ├── osenv@0.0.3
  ├─┬ read@1.0.4
  │ └── mute-stream@0.0.3
  ├── read-installed@0.1.1
  ├── read-package-json@0.2.2
  ├── request@2.9.203
  ├── retry@0.6.0
  ├── rimraf@2.1.4
  ├── semver@1.1.4
  ├── slide@1.1.3
  ├── tar@0.1.16
  ├── uid-number@0.0.3
  └── which@1.0.5

npm ERR! missing: serialport@0.7.5, required by bonescript@0.2.2
npm ERR! not ok code 0

ふむふむ、bonescriptはもちろん、express, socket.io, serialportなどがグローバルインストールされていました。ということは、AngstromのままでもNode.jsでプログラム書いて動かして遊ぶのもいいですね