安裝環境: Ubuntu 14.04 64-bithtml
NodeJs安裝node
官網 https://nodejs.org 速度太慢linux
國內鏡像: https://npm.taobao.org/dist 下對應版本便可android
下載: node-v4.2.1-linux-x64.tar.gz 解壓git
查看bin目錄: node, npm. $node/bin 這個目錄加到PATH中, 或是連接 node, npm到/usr/bin中github
node -v 查看是否安裝成功, NodeJs到此安裝完成.web
1.1 配置npm的模塊全局安裝目錄 (暫且跳過):npm
#先查看配置 npm config ls 瀏覽器
#設置 npm config set prefix '~/nodejs/module'app
#將 {prefix}/bin 即: ~/nodejs/module/bin 加入到 PATH中, 才能在命令行中直接用模塊命令
#PATH修改後記得從新source才能生效
1.2 npm使用國內淘寶鏡像
使用淘寶定製的 cnpm (gzip 壓縮支持) 命令行工具代替默認的 npm
:
命令以下:
npm install -g cnpm --registry=https://registry.npm.taobao.org
安裝模塊
$ cnpm install [name]
同步模塊
$ cnpm sync connect
2. Cordova安裝
sudo cnpm install -g cordova 便可
3. ionic 安裝
sudo cnpm install -g ionic
安裝過程當中如出現: npm ERR! tar.unpack untar error /tmp/npm
先執行
sudo npm cache clean
而後從新安裝
若遇到錯誤以下:
npm ERR! spawn-sync@1.0.13 postinstall: `node postinstall`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the spawn-sync@1.0.13 postinstall script 'node postinstall'.
npm ERR! This is most likely a problem with the spawn-sync package,
npm ERR! not with npm itself.
===================================================
解決方法: sudo cnpm install --ignore-scripts -g cordova ionic
參考:https://github.com/ForbesLindesay/spawn-sync/issues/29
first ionic web app
http://ionicframework.com/getting-started/
$ ionic start myApp tabs $ cd myApp $ ionic platform add android $ ionic build android $ ionic emulate android // 模擬器 $ ionic run android // 測試設備
入門教程: http://ionicframework.com/docs/guide/starting.html 看完內心就踏實了, 固然可能要補一下AngularJs的基礎知識.
推薦桌面瀏覽器測試:
$ ionic serve Multiple addresses available. Please select which address to use by entering its number from the list below: 1) 10.10.10.17 (eth0) 2) localhost Address Selection: 2 Selected address: localhost Running live reload server: http://localhost:35729 Watching: 0=www/**/*, 1=!www/lib/**/* Running dev server:
瀏覽器輸入地址便可
http://localhost:8100
=======================================================
ionic build android Error
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.] |
需安裝 android SDK, cordova 5.3.3版本對SDK版本android-22, 通常下載最新版本
You will require: 1. "SDK Platform" for android-22 2. "Android SDK Platform-tools (latest) 3. "Android SDK Build-tools" (latest)] |
國內能夠在這裏下載 http://www.androiddevtools.cn/
推薦鏡像更新方式: http://android-mirror.bugly.qq.com:8080/include/usage.html
並設置環境變量 ANDROID_HOME 及 PATH
export ANDROID_HOME=~/sdk
export PATH=$PATH:$ANDROID_HOME\tools:$ANDROID_HOME\platform-tools