- 安装 node.js,可以从 https://nodejs.org 下载安装包
安装完成后,通过node -v
命令可以查看版本,例如:v4.4.7 - 使用 HomeBrew 安装 watchman 和 flow
brow install watchman
brow install flow
安装 watchman 的时候会自动安装依赖的 pcre
bash-3.2# brew install watchman
==> Installing dependencies for watchman: pcre
==> Installing watchman dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.39.yosemite.bottle.t
######################################################################## 100.0%
==> Pouring pcre-8.39.yosemite.bottle.tar.gz
Error: Thebrew link
step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pcre-config
Target /usr/local/bin/pcre-config
already exists. You may want to remove it:
rm '/usr/local/bin/pcre-config'
To force the link and overwrite all conflicting files:
brew link --overwrite pcre
To list all files that would be deleted:
brew link --overwrite --dry-run pcre
Possible conflicting files are:
/usr/local/bin/pcre-config
/usr/local/bin/pcregrep
/usr/local/bin/pcretest
/usr/local/include/pcre.h
/usr/local/include/pcre_scanner.h
/usr/local/include/pcre_stringpiece.h
/usr/local/include/pcrecpp.h
/usr/local/include/pcrecpparg.h
/usr/local/include/pcreposix.h
/usr/local/share/doc/pcre/AUTHORS
/usr/local/share/doc/pcre/COPYING
/usr/local/share/doc/pcre/ChangeLog
/usr/local/share/doc/pcre/LICENCE
/usr/local/share/doc/pcre/NEWS
/usr/local/share/doc/pcre/README
/usr/local/share/doc/pcre/html/NON-AUTOTOOLS-BUILD.txt
/usr/local/share/doc/pcre/html/README.txt
/usr/local/share/doc/pcre/html/index.html
/usr/local/share/doc/pcre/html/pcre-config.html
/usr/local/share/doc/pcre/html/pcre.html
/usr/local/share/doc/pcre/html/pcre16.html
/usr/local/share/doc/pcre/html/pcre32.html
/usr/local/share/doc/pcre/html/pcre_assign_jit_stack.html
/usr/local/share/doc/pcre/html/pcre_compile.html
/usr/local/share/doc/pcre/html/pcre_compile2.html
/usr/local/share/doc/pcre/html/pcre_config.html
/usr/local/share/doc/pcre/html/pcre_copy_named_substring.html
/usr/local/share/doc/pcre/html/pcre_copy_substring.html
/usr/local/share/doc/pcre/html/pcre_dfa_exec.html
/usr/local/share/doc/pcre/html/pcre_exec.html
/usr/local/share/doc/pcre/html/pcre_free_study.html
/usr/local/share/doc/pcre/html/pcre_free_substring.html
/usr/local/share/doc/pcre/html/pcre_free_substring_list.html
/usr/local/share/doc/pcre/html/pcre_fullinfo.html
/usr/local/share/doc/pcre/html/pcre_get_named_substring.html
/usr/local/share/doc/pcre/html/pcre_get_stringnumber.html
/usr/local/share/doc/pcre/html/pcre_get_stringtable_entries.html
/usr/local/share/doc/pcre/html/pcre_get_substring.html
/usr/local/share/doc/pcre/html/pcre_get_substring_list.html
/usr/local/share/doc/pcre/html/pcre_jit_exec.html
/usr/local/share/doc/pcre/html/pcre_jit_stack_alloc.html
/usr/local/share/doc/pcre/html/pcre_jit_stack_free.html
/usr/local/share/doc/pcre/html/pcre_maketables.html
/usr/local/share/doc/pcre/html/pcre_pattern_to_host_byte_order.html
/usr/local/share/doc/pcre/html/pcre_refcount.html
/usr/local/share/doc/pcre/html/pcre_study.html
/usr/local/share/doc/pcre/html/pcre_utf16_to_host_byte_order.html
/usr/local/share/doc/pcre/html/pcre_utf32_to_host_byte_order.html
/usr/local/share/doc/pcre/html/pcre_version.html
/usr/local/share/doc/pcre/html/pcreapi.html
/usr/local/share/doc/pcre/html/pcrebuild.html
/usr/local/share/doc/pcre/html/pcrecallout.html
/usr/local/share/doc/pcre/html/pcrecompat.html
/usr/local/share/doc/pcre/html/pcrecpp.html
/usr/local/share/doc/pcre/html/pcredemo.html
/usr/local/share/doc/pcre/html/pcregrep.html
/usr/local/share/doc/pcre/html/pcrejit.html
/usr/local/share/doc/pcre/html/pcrelimits.html
/usr/local/share/doc/pcre/html/pcrematching.html
/usr/local/share/doc/pcre/html/pcrepartial.html
/usr/local/share/doc/pcre/html/pcrepattern.html
/usr/local/share/doc/pcre/html/pcreperform.html
/usr/local/share/doc/pcre/html/pcreposix.html
/usr/local/share/doc/pcre/html/pcreprecompile.html
/usr/local/share/doc/pcre/html/pcresample.html
/usr/local/share/doc/pcre/html/pcrestack.html
/usr/local/share/doc/pcre/html/pcresyntax.html
/usr/local/share/doc/pcre/html/pcretest.html
/usr/local/share/doc/pcre/html/pcreunicode.html
/usr/local/share/doc/pcre/pcre-config.txt
/usr/local/share/doc/pcre/pcre.txt
/usr/local/share/doc/pcre/pcregrep.txt
/usr/local/share/doc/pcre/pcretest.txt
/usr/local/share/man/man1/pcre-config.1
/usr/local/share/man/man1/pcregrep.1
/usr/local/share/man/man1/pcretest.1
/usr/local/share/man/man3/pcre.3
/usr/local/share/man/man3/pcre16.3
/usr/local/share/man/man3/pcre16_assign_jit_stack.3 -> /usr/local/share/man/man3/pcre_assign_jit_stack.3
/usr/local/share/man/man3/pcre16_compile.3 -> /usr/local/share/man/man3/pcre_compile.3
/usr/local/share/man/man3/pcre16_compile2.3 -> /usr/local/share/man/man3/pcre_compile2.3
/usr/local/share/man/man3/pcre16_config.3 -> /usr/local/share/man/man3/pcre_config.3
/usr/local/share/man/man3/pcre16_copy_named_substring.3 -> /usr/local/share/man/man3/pcre_copy_named_substring.3
/usr/local/share/man/man3/pcre16_copy_substring.3 -> /usr/local/share/man/man3/pcre_copy_substring.3
/usr/local/share/man/man3/pcre16_dfa_exec.3 -> /usr/local/share/man/man3/pcre_dfa_exec.3
/usr/local/share/man/man3/pcre16_exec.3 -> /usr/local/share/man/man3/pcre_exec.3
/usr/local/share/man/man3/pcre16_free_study.3 -> /usr/local/share/man/man3/pcre_free_study.3
/usr/local/share/man/man3/pcre16_free_substring.3 -> /usr/local/share/man/man3/pcre_free_substring.3
/usr/local/share/man/man3/pcre16_free_substring_list.3 -> /usr/local/share/man/man3/pcre_free_substring_list.3
/usr/local/share/man/man3/pcre16_fullinfo.3 -> /usr/local/share/man/man3/pcre_fullinfo.3
/usr/local/share/man/man3/pcre16_get_named_substring.3 -> /usr/local/share/man/man3/pcre_get_named_substring.3
/usr/local/share/man/man3/pcre16_get_stringnumber.3 -> /usr/local/share/man/man3/pcre_get_stringnumber.3
/usr/local/share/man/man3/pcre16_get_stringtable_entries.3 -> /usr/local/share/man/man3/pcre_get_stringtable_entries.3
/usr/local/share/man/man3/pcre16_get_substring.3 -> /usr/local/share/man/man3/pcre_get_substring.3
/usr/local/share/man/man3/pcre16_get_substring_list.3 -> /usr/local/share/man/man3/pcre_get_substring_list.3
/usr/local/share/man/man3/pcre16_jit_exec.3 -> /usr/local/share/man/man3/pcre_jit_exec.3
/usr/local/share/man/man3/pcre16_jit_stack_alloc.3 -> /usr/local/share/man/man3/pcre_jit_stack_alloc.3
/usr/local/share/man/man3/pcre16_jit_stack_free.3 -> /usr/local/share/man/man3/pcre_jit_stack_free.3
/usr/local/share/man/man3/pcre16_maketables.3 -> /usr/local/share/man/man3/pcre_maketables.3
/usr/local/share/man/man3/pcre16_pattern_to_host_byte_order.3 -> /usr/local/share/man/man3/pcre_pattern_to_host_byte_order.3
/usr/local/share/man/man3/pcre16_refcount.3 -> /usr/local/share/man/man3/pcre_refcount.3
/usr/local/share/man/man3/pcre16_study.3 -> /usr/local/share/man/man3/pcre_study.3
/usr/local/share/man/man3/pcre16_utf16_to_host_byte_order.3 -> /usr/local/share/man/man3/pcre_utf16_to_host_byte_order.3
/usr/local/share/man/man3/pcre16_version.3 -> /usr/local/share/man/man3/pcre_version.3
/usr/local/share/man/man3/pcre32.3
/usr/local/share/man/man3/pcre32_assign_jit_stack.3 -> /usr/local/share/man/man3/pcre_assign_jit_stack.3
/usr/local/share/man/man3/pcre32_compile.3 -> /usr/local/share/man/man3/pcre_compile.3
/usr/local/share/man/man3/pcre32_compile2.3 -> /usr/local/share/man/man3/pcre_compile2.3
/usr/local/share/man/man3/pcre32_config.3 -> /usr/local/share/man/man3/pcre_config.3
/usr/local/share/man/man3/pcre32_copy_named_substring.3 -> /usr/local/share/man/man3/pcre_copy_named_substring.3
/usr/local/share/man/man3/pcre32_copy_substring.3 -> /usr/local/share/man/man3/pcre_copy_substring.3
/usr/local/share/man/man3/pcre32_dfa_exec.3 -> /usr/local/share/man/man3/pcre_dfa_exec.3
/usr/local/share/man/man3/pcre32_exec.3 -> /usr/local/share/man/man3/pcre_exec.3
/usr/local/share/man/man3/pcre32_free_study.3 -> /usr/local/share/man/man3/pcre_free_study.3
/usr/local/share/man/man3/pcre32_free_substring.3 -> /usr/local/share/man/man3/pcre_free_substring.3
/usr/local/share/man/man3/pcre32_free_substring_list.3 -> /usr/local/share/man/man3/pcre_free_substring_list.3
/usr/local/share/man/man3/pcre32_fullinfo.3 -> /usr/local/share/man/man3/pcre_fullinfo.3
/usr/local/share/man/man3/pcre32_get_named_substring.3 -> /usr/local/share/man/man3/pcre_get_named_substring.3
/usr/local/share/man/man3/pcre32_get_stringnumber.3 -> /usr/local/share/man/man3/pcre_get_stringnumber.3
/usr/local/share/man/man3/pcre32_get_stringtable_entries.3 -> /usr/local/share/man/man3/pcre_get_stringtable_entries.3
/usr/local/share/man/man3/pcre32_get_substring.3 -> /usr/local/share/man/man3/pcre_get_substring.3
/usr/local/share/man/man3/pcre32_get_substring_list.3 -> /usr/local/share/man/man3/pcre_get_substring_list.3
/usr/local/share/man/man3/pcre32_jit_exec.3 -> /usr/local/share/man/man3/pcre_jit_exec.3
/usr/local/share/man/man3/pcre32_jit_stack_alloc.3 -> /usr/local/share/man/man3/pcre_jit_stack_alloc.3
/usr/local/share/man/man3/pcre32_jit_stack_free.3 -> /usr/local/share/man/man3/pcre_jit_stack_free.3
/usr/local/share/man/man3/pcre32_maketables.3 -> /usr/local/share/man/man3/pcre_maketables.3
/usr/local/share/man/man3/pcre32_pattern_to_host_byte_order.3 -> /usr/local/share/man/man3/pcre_pattern_to_host_byte_order.3
/usr/local/share/man/man3/pcre32_refcount.3 -> /usr/local/share/man/man3/pcre_refcount.3
/usr/local/share/man/man3/pcre32_study.3 -> /usr/local/share/man/man3/pcre_study.3
/usr/local/share/man/man3/pcre32_utf32_to_host_byte_order.3 -> /usr/local/share/man/man3/pcre_utf32_to_host_byte_order.3
/usr/local/share/man/man3/pcre32_version.3 -> /usr/local/share/man/man3/pcre_version.3
/usr/local/share/man/man3/pcre_assign_jit_stack.3
/usr/local/share/man/man3/pcre_compile.3
/usr/local/share/man/man3/pcre_compile2.3
/usr/local/share/man/man3/pcre_config.3
/usr/local/share/man/man3/pcre_copy_named_substring.3
/usr/local/share/man/man3/pcre_copy_substring.3
/usr/local/share/man/man3/pcre_dfa_exec.3
/usr/local/share/man/man3/pcre_exec.3
/usr/local/share/man/man3/pcre_free_study.3
/usr/local/share/man/man3/pcre_free_substring.3
/usr/local/share/man/man3/pcre_free_substring_list.3
/usr/local/share/man/man3/pcre_fullinfo.3
/usr/local/share/man/man3/pcre_get_named_substring.3
/usr/local/share/man/man3/pcre_get_stringnumber.3
/usr/local/share/man/man3/pcre_get_stringtable_entries.3
/usr/local/share/man/man3/pcre_get_substring.3
/usr/local/share/man/man3/pcre_get_substring_list.3
/usr/local/share/man/man3/pcre_jit_exec.3
/usr/local/share/man/man3/pcre_jit_stack_alloc.3
/usr/local/share/man/man3/pcre_jit_stack_free.3
/usr/local/share/man/man3/pcre_maketables.3
/usr/local/share/man/man3/pcre_pattern_to_host_byte_order.3
/usr/local/share/man/man3/pcre_refcount.3
/usr/local/share/man/man3/pcre_study.3
/usr/local/share/man/man3/pcre_utf16_to_host_byte_order.3
/usr/local/share/man/man3/pcre_utf32_to_host_byte_order.3
/usr/local/share/man/man3/pcre_version.3
/usr/local/share/man/man3/pcreapi.3
/usr/local/share/man/man3/pcrebuild.3
/usr/local/share/man/man3/pcrecallout.3
/usr/local/share/man/man3/pcrecompat.3
/usr/local/share/man/man3/pcrecpp.3
/usr/local/share/man/man3/pcredemo.3
/usr/local/share/man/man3/pcrejit.3
/usr/local/share/man/man3/pcrelimits.3
/usr/local/share/man/man3/pcrematching.3
/usr/local/share/man/man3/pcrepartial.3
/usr/local/share/man/man3/pcrepattern.3
/usr/local/share/man/man3/pcreperform.3
/usr/local/share/man/man3/pcreposix.3
/usr/local/share/man/man3/pcreprecompile.3
/usr/local/share/man/man3/pcresample.3
/usr/local/share/man/man3/pcrestack.3
/usr/local/share/man/man3/pcresyntax.3
/usr/local/share/man/man3/pcreunicode.3
/usr/local/lib/libpcre.1.dylib
/usr/local/lib/libpcre.a
/usr/local/lib/libpcre.dylib -> /usr/local/lib/libpcre.1.dylib
/usr/local/lib/libpcrecpp.0.dylib
/usr/local/lib/libpcrecpp.a
/usr/local/lib/libpcrecpp.dylib -> /usr/local/lib/libpcrecpp.0.dylib
/usr/local/lib/libpcreposix.0.dylib
/usr/local/lib/libpcreposix.a
/usr/local/lib/libpcreposix.dylib -> /usr/local/lib/libpcreposix.0.dylib
/usr/local/lib/pkgconfig/libpcre.pc
/usr/local/lib/pkgconfig/libpcrecpp.pc
/usr/local/lib/pkgconfig/libpcreposix.pc
==> Summary
🍺 /usr/local/Cellar/pcre/8.39: 203 files, 5.4M
==> Installing watchman
==> Downloading https://homebrew.bintray.com/bottles/watchman-4.6.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring watchman-4.6.0.yosemite.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again usingbrew postinstall watchman
==> Summary
🍺 /usr/local/Cellar/watchman/4.6.0: 21 files, 397K
接下来安装 flow
bash-3.2# brew install flow
==> Downloading https://homebrew.bintray.com/bottles/flow-0.28.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring flow-0.28.0.yosemite.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completion has been installed to:
/usr/local/share/zsh/site-functions
==> Summary
🍺 /usr/local/Cellar/flow/0.28.0: 7 files, 4.6M
- 使用 npm 安装 react-native-cli
bash-3.2# npm install -g react-native-cli
/usr/local/bin/react-native -> /usr/local/lib/node_modules/react-native-cli/index.js
react-native-cli@1.0.0 /usr/local/lib/node_modules/react-native-cli
├── semver@5.3.0
├── minimist@1.2.0
├── chalk@1.1.3 (ansi-styles@2.2.1, supports-color@2.0.0, escape-string-regexp@1.0.5, strip-ansi@3.0.1, has-ansi@2.0.0)
└── prompt@0.2.14 (revalidator@0.1.8, pkginfo@0.4.0, read@1.0.7, winston@0.8.3, utile@0.2.1)
至此,所有依赖安装完成,可以开始创建工程了。
bash-3.2# react-native init HelloWorld
This will walk you through creating a new React Native project in /Users/admin/Documents/projects/reactnative/HelloWorld
Installing react-native package from npm...
Setting up new React Native app in /Users/admin/Documents/projects/reactnative/HelloWorld
react@15.2.1 node_modules/react
├── object-assign@4.1.0
├── loose-envify@1.2.0 (js-tokens@1.0.3)
└── fbjs@0.8.3 (immutable@3.8.1, ua-parser-js@0.7.10, promise@7.1.1, isomorphic-fetch@2.2.1, core-js@1.2.7)
To run your app on iOS:
cd /Users/admin/Documents/projects/reactnative/HelloWorld
react-native run-ios
- or -
Open /Users/admin/Documents/projects/reactnative/HelloWorld/ios/HelloWorld.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
Have an Android emulator running (quickest way to get started), or a device connected
cd /Users/admin/Documents/projects/reactnative/HelloWorld
react-native run-android