[Cubieboard] 在Cubieboard上安裝Node.js和npm

來源:互聯網
上載者:User

標籤:style   c   class   blog   code   java   

你有兩個選擇可以實現在Cubieboard上安裝NodeJS,下載別人已經編譯完成適用於Cubieboard的NodeJS二進位包,或者自己下載源碼自行在Cubieboard上進行編譯。

 

使用編譯完成的二進位包

在這裡下載適用於ARM架構的Node.js,如果在Cubieboard社區找不到相關資源,可以在RaspberryPi社區尋找相近的資源。例如在《Node.js installation for Raspberry Pi》一文中提供了最新的適用於RaspberryPi的Node.js可執行包下載,這裡同樣了提供了可執行二進位包下載,但要注意它們所針對的RaspberryPi所使用的晶片,未必適合於Cubieboard2,但值得嘗試一下,拓展一下思路。

 

從源碼包編譯安裝Node.js

(本文以BeagleBone為例)

相比於常見的使用Cross-complie來編譯適用於ARM架構的可執行包,你也可以在Cubieboard(原文是在BeagleBone上編譯,本文是在Cubieboard的Lubuntu上進行編譯)上直接編譯,但這樣做會消耗更長的一點時間。

Compile和Install操作時請使用sudo或者su切換到root許可權。

 

第一步:準備工作

首先你需要一個編譯器來編譯NodeJS源碼。Build過程需要Python來處理一些設定檔,另外需要GCC來處理真正的原始碼。

# apt-get install python# apt-get install build-essential

 

第二步:下載Node原始碼

從Node.js官網下載最新的原始碼。截至本文落筆時最新的NodeJS版本為0.10.28(原文為0.10.5)。本文直接將源碼包解壓至當前檔案夾,你可以使用-C <path>選項來指定解壓路徑。

# wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz# tar xzvf node-v0.10.28.tar.gz

 

第三步:配置

截至原文落筆時,Google的V8引擎Snapshot功能會導致Node發生segmentation fault。Snapshotting可以協助Node以更快的速度啟動,但這不是一個很重要的特性,因此編譯時間可以忽略它。

# cd node-v0.10.28# ./configure --without-snapshot

列印的配置結果:

{ ‘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‘: ‘‘,                 ‘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‘}}creating  ./config.gypicreating  ./config.mk

 

第四步:編譯

開始編譯,編譯時間大概在30-40分鐘左右吧。

# make

 

第五步:確認編譯是否成功

當Build完成時,我們可以確認一下編譯是否成功,然後再進行安裝。

# ./node -e ‘console.log("hello, world");‘# ./node -v

本文確認結果為可以正確列印Node版本號碼,但不能執行node命令,同樣狀況出現在npm身上。

 

第六步:安裝

# make install

 

如果已經安裝了,可以使用make uninstall進行卸載。

 

結束語

由於本次在Cubieboard上進行的natively compile沒有成功,最後還是使用了"Node.js installation for Raspberry Pi"一文中所提供的先行編譯檔案在Cubieboard2上成功安裝了NodeJS-0.10.28及npm-1.4.9。

1. 下載安裝包

$ wget http://node-arm.herokuapp.com/node_latest_armhf.deb

本文落筆時NodeJS最新版本為0.10.28,因此下載了該版本。

 

2. 安裝

$ sudo dpkg -i node_0.10.28-1_armhf.deb Selecting previously unselected package node.(Reading database ... 165570 files and directories currently installed.)Unpacking node (from node_0.10.28-1_armhf.deb) ...Setting up node (0.10.28-1) ...Processing triggers for man-db ...

 

3. 驗證

$ node -e ‘console.log("hello, world");‘hello, world$ node -vv0.10.28$ npm -v1.4.9

 

 

參考:Node.js for the BeagleBone Black

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.