虽然kali自带了nodejs,但是并不是最新的,所以更新一下。
运行:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
结果:
## Installing the NodeSource Node.js v6.x repo...
## Populating apt-get cache...
+ apt-get update
命中:1 http://mirrors.aliyun.com/kali sana InRelease
命中:2 http://mirrors.aliyun.com/kali-security sana/updates InRelease
获取:3 http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling InRelease [30.5 kB]
获取:4 http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling/main i386 Packages [14.2 MB]
忽略:5 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 InRelease
命中:6 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 Release
获取:7 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 Release.gpg [801 B]
获取:8 http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling/main amd64 Packages [14.2 MB]
已下载 28.5 MB,耗时 3分 20秒 (142 kB/s)
正在读取软件包列表... 完成
## Installing packages required for setup: apt-transport-https...
+ apt-get install -y apt-transport-https > /dev/null 2>&1
## You seem to be using Kali version kali-rolling.
## This maps to Debian "jessie"... Adjusting for you...
## Confirming "jessie" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_6.x/dists/jessie/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK
## Creating apt sources list file for the NodeSource Node.js v6.x repo...
+ echo 'deb https://deb.nodesource.com/node_6.x jessie main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_6.x jessie main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
命中:1 http://mirrors.aliyun.com/kali sana InRelease
命中:2 http://mirrors.aliyun.com/kali-security sana/updates InRelease
命中:3 http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling InRelease
忽略:4 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 InRelease
命中:5 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 Release
获取:6 https://deb.nodesource.com/node_6.x jessie InRelease [3,914 B]
获取:7 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.2 Release.gpg [801 B]
获取:8 https://deb.nodesource.com/node_6.x jessie/main Sources [760 B]
获取:9 https://deb.nodesource.com/node_6.x jessie/main amd64 Packages [961 B]
获取:10 https://deb.nodesource.com/node_6.x jessie/main i386 Packages [958 B]
已下载 7,394 B,耗时 2秒 (3,059 B/s)
正在读取软件包列表... 完成
## Run `apt-get install nodejs` (as root) to install Node.js v6.x and npm
完成更新:
运行:
apt-get install nodejs
结果:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
libuv1 libxcb-randr0:i386 libxcb-shape0:i386 libxcb-xfixes0:i386
使用'apt autoremove'来卸载它(它们)。
下列软件包将被升级:
nodejs
升级了 1 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 223 个软件包未被升级。
需要下载 10.1 MB 的归档。
解压缩后会消耗 37.5 MB 的额外空间。
获取:1 https://deb.nodesource.com/node_6.x jessie/main amd64 nodejs amd64 6.9.1-1nodesource1~jessie1 [10.1 MB]
已下载 10.1 MB,耗时 19秒 (531 kB/s)
读取变更记录(changelogs)... 完成
(正在读取数据库 ... 系统当前共安装有 390887 个文件和目录。)
正准备解包 .../nodejs_6.9.1-1nodesource1~jessie1_amd64.deb ...
正在将 nodejs (6.9.1-1nodesource1~jessie1) 解包到 (4.3.1~dfsg-3) 上 ...
正在设置 nodejs (6.9.1-1nodesource1~jessie1) ...
正在处理用于 man-db (2.7.5-1) 的触发器 ...
然后查看各个版本:
root@jimo:~# node -v
v6.9.1
root@jimo:~# nodejs -v
v6.9.1
root@jimo:~# npm -v
3.10.8
因为中国访问npm很慢,所以借助淘宝的:https://npm.taobao.org/
运行安装:
root@jimo:~# npm install -g cnpm --registry=https://registry.npm.taobao.org
结果:
npm WARN deprecated has-color@0.1.7: Renamed to supports-color. If you're using chalk, upgrade to the latest version. https://github.com/chalk/supports-color
/usr/bin/cnpm -> /usr/lib/node_modules/cnpm/bin/cnpm
/usr/lib
└─┬ cnpm@4.4.0
├── auto-correct@1.0.0
├── bagpipe@0.3.5
├── colors@1.1.2
├─┬ commander@2.9.0
│ └── graceful-readlink@1.0.1
├─┬ cross-spawn@0.2.9
│ └── lru-cache@2.7.3
├─┬ debug@2.2.0
│ └── ms@0.7.1
├── giturl@1.0.0
├─┬ npm@3.10.9
│ ├── abbrev@1.0.9
│ ├── ansi-regex@2.0.0
│ ├── ansicolors@0.3.2
│ ├── ansistyles@0.1.3
│ ├── aproba@1.0.4
......后面还有n多输出
查看版本:
root@jimo:~# cnpm -v
4.4.0
运行:
root@jimo:~# cnpm install nativescript -g --unsafe-perm
结果:
⠴ Installing nativescript@*install bufferutil from remote https://github.com/telerik/bufferutil/tarball/v1.0.1.3, may be very slow, please keep patience
install cli-table from remote https://github.com/telerik/cli-table/tarball/v0.3.1.2, may be very slow, please keep patience
install ffi from remote https://github.com/icenium/node-ffi/tarball/v2.0.0.3, may be very slow, please keep patience
install fibers from remote https://github.com/icenium/node-fibers/tarball/v1.0.13.1, may be very slow, please keep patience
install node-inspector from remote https://github.com/NativeScript/node-inspector/tarball/v0.7.4.1, may be very slow, please keep patience..........后面还有n多输出
然后查看是否安装成功:
root@jimo:~# tns doctor
NOTE: You can develop for iOS only on Mac OS X systems.
To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later.
You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=24'.
Run android from your command-line to install required Android Build Tools.
There seem to be issues with your configuration.
? Do you want to visit the official documentation? No
Your components are up-to-date.
When you file an issue, these warnings will help the NativeScript team to investigate, identify, and resolve the report.
Please, ignore them if you are not experiencing any issues with NativeScript.
或者查看帮助命令:
root@jimo:~# tns -h
# NativeScript
┌─────────┬─────────────────────────────────────────────────────────────────────┐
│ Usage │ Synopsis │
│ General │ $ tns <Command> [Command Parameters] [--command <Options>] │
│ Alias │ $ nativescript <Command> [Command Parameters] [--command <Options>] │
└─────────┴─────────────────────────────────────────────────────────────────────┘
## General Commands
┌─────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Command │ Description │
│ help <Command> │ Shows additional information about the commands in this list in the browser. │
│ autocomplete │ Configures your current command-line completion settings. │
│ usage-reporting │ Configures anonymous usage reporting for the NativeScript CLI. │
│ error-reporting │ Configures anonymous error reporting for the NativeScript CLI. │
│ doctor │ Checks your system for configuration problems which might prevent the NativeScript CLI from working properly. │
│ info │ Displays version information about the NativeScript CLI, core modules, and runtimes. │
└─────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
## Project Development Commands
┌────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Command │ Description │
│ create │ Creates a new project for native development with NativeScript. │
│ init │ Initializes an existing project for native development with NativeScript. │
│ platform add <Platform> │ Configures the current project to target the selected platform. │
│ platform list │ Lists all platforms that the project currently targets. │
│ platform remove <Platform> │ Removes the selected platform from the platforms that the project currently targets. This operation deletes all platform-specific files and subdirectories from your project. │
│ platform update <Platform> │ Updates the NativeScript runtime for the specified platform. │
│ prepare <Platform> │ Copies relevant content from the app directory to the subdirectory for the selected target platform to let you build the project. │
│ build <Platform> │ Builds the project for the selected target platform and produces an application package or an emulator package. │
│ deploy <Platform> │ Deploys the project to a connected physical or virtual device. │
│ emulate <Platform> │ Deploys the project in the native emulator for the selected target platform. │
│ run <Platform> │ Runs your project on a connected device or in the native emulator, if configured. │
│ debug <Platform> │ Debugs your project on a connected physical or virtual device. │
│ test init │ Configures your project for unit testing with a selected framework. │
│ test <Platform> │ Runs the unit tests in your project on a connected physical or virtual device. │
│ install │ Installs all platforms and dependencies described in the package.json file in the current directory. │
│ plugin │ Lets you manage the plugins for your project. │
│ livesync │ Synchronizes the latest changes in your project to devices. │
└────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
## Publishing Commands
┌─────────────────┬──────────────────────────────────────────────────┐
│ Command │ Description │
│ appstore │ Lists applications registered in iTunes Connect. │
│ appstore upload │ Uploads project to iTunes Connect. │
└─────────────────┴──────────────────────────────────────────────────┘
## Device Commands
┌──────────────────────────┬─────────────────────────────────────────────────────────────┐
│ Command │ Description │
│ device │ Lists all recognized connected physical or virtual devices. │
│ device log │ Opens the log stream for the selected device. │
│ device run │ Runs the selected application on a connected device. │
│ device list-applications │ Lists the installed applications on all connected devices. │
└──────────────────────────┴─────────────────────────────────────────────────────────────┘
## Global Options
┌────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Option │ Description │
│ --help, -h, /? │ Prints help about the selected command in the console. │
│ --path <Directory> │ Specifies the directory that contains the project. If not set, the project is searched for in the current directory and all directories above it. │
│ --version │ Prints the client version. │
│ --log trace │ Prints a detailed diagnostic log for the execution of the current command. │
└────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
root@jimo
到目前为止我还没提android环境,因为你可以通过它去下载需要的sdk,后面会提到。
到你的工作目录下去git下来项目:
# git clone https://github.com/NativeScript/sample-Groceries.git
正克隆到 'sample-Groceries'...
remote: Counting objects: 5838, done.
接收对象中: 34% (2031/5838), 16.60 MiB | 54.00 KiB/s
remote: Total 5838 (delta 0), reused 0 (delta 0), pack-reused 5838
接收对象中: 100% (5838/5838), 56.75 MiB | 918.00 KiB/s, 完成.
处理 delta 中: 100% (2852/2852), 完成.
然后进入工程目录checkout:
/sample-Groceries# git checkout start
分支 start 设置为跟踪来自 origin 的远程分支 start。
切换到一个新分支 'start'
如果现在运行,必须在项目下添加环境:
/sample-Groceries# tns platform add android
Copying template files...
◡ Installing tns-android\
You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=24'.
然后它提示我没有找到,于是我们可以先安装:
在命令行运行android,去安装它所要求的android版本,上面是23到24:
完成后再次运行就成功了:
/sample-Groceries# tns platform add android
Copying template files...
Project successfully created.
然后我们可以试着真机运行:
不过首先得获取到手机的id,如下命令:
# tns device android
┌───┬─────────────┬──────────┬───────────────────┬────────┬───────────┐
│ # │ Device Name │ Platform │ Device Identifier │ Type │ Status │
│ 1 │ hennessy │ Android │ 5TWWTSOVOFYDMFUC │ Device │ Connected │
└───┴─────────────┴──────────┴───────────────────┴────────┴───────────┘
然后运行:
/sample-Groceries# tns run android --device 5TWWTSOVOFYDMFUC
最后这会是一个比较漫长的过程,如果是第一次运行的话,他回去下载gradle构建工具等一系列文件,直到最后看见:
Result is 1910 defs/2248.4KiB. Took 0.4s
:mergeF0DebugJniLibFolders
:transformNative_libsWithMergeJniLibsForF0Debug
:processF0DebugJavaRes UP-TO-DATE
:transformResourcesWithMergeJavaResForF0Debug
:validateDebugSigning
:packageF0Debug
:zipalignF0Debug
:assembleF0Debug
:assembleDebug
:buildapk
BUILD SUCCESSFUL
Total time: 34.385 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
Project successfully built
Successfully deployed on device with identifier '5TWWTSOVOFYDMFUC'.
所以经历了这么多,真机测试不是最好的,下节介绍安装模拟器。