MacOS 配置 React Native 开发环境

  • 安装 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: The brew 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 using brew 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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,126评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,254评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,445评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,185评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,178评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,970评论 1 284
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,276评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,927评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,400评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,883评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,997评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,646评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,213评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,204评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,423评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,423评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,722评论 2 345

推荐阅读更多精彩内容