安装环境: Ubuntu 14.04 64-bit
NodeJs安装
官网 https://nodejs.org 速度太慢
国内镜像: https://npm.taobao.org/dist 下对应版本即可
下载: node-v4.2.1-linux-x64.tar.gz 解压
查看bin目录: node, npm. $node/bin 这个目录加到PATH中, 或是链接 node, npm到/usr/bin中
node -v 查看是否安装成功, NodeJs到此安装完成.
1.1 配置npm的模块全局安装目录 (暂且跳过):
#先查看配置 npm config ls
#设置 npm config set prefix '~/nodejs/module'
#将 {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
来源:oschina
链接:https://my.oschina.net/u/2485194/blog/517232