react native mac install

Mac上使用react native tips:

1. 安装Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. 安装nvm 和 node

nvm:

  touch ~/.bash_profile                   -》 环境变量在安装过程中写入

  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash -》安装后创建~/.nvm

  nvm

node

  nvm install node && nvm alias default node   -》 系统级别的node_modules安装在~/.nvm/versions/node/v5.7.1/lib下面

  node

 

3. 安装watchman 和 flow

  brew install watchman

  brew install flow

  brew update && brew upgrade

4. 创建Project

  npm install -g react-native-cli     -> 安装react-native 命令到/Users/XXX/.nvm/versions/node/v5.7.1/bin/react-native

下面

  react-native init AwesomeProject   -> 下载npm包, 可以在目录下执行npm start和npm install

5.  试用Project

  会运行一个node server处理请求

  改动index.ios.js,cmd+R可以在线刷新页面

  

install log

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100  7766  100  7766    0     0   3012      0  0:00:02  0:00:02 --:--:--  3012

=> nvm is already installed in /Users/XXX/.nvm, trying to update using git

=> 

=> Appending source string to /Users/XXX/.bash_profile

=> You currently have modules installed globally with `npm`. These will no

=> longer be linked to the active version of Node when you install a new node

=> with `nvm`; and they may (depending on how you construct your `$PATH`)

=> override the binaries of modules installed with `nvm`:

/Users/XXX/.nvm/versions/node/v5.7.1/lib

└── react-native-cli@0.1.10

=> If you wish to uninstall them at a later point (or re-install them under your

=> `nvm` Nodes), you can remove them from the system Node as follows:

     $ nvm use system

     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm

node Server log

~/react-native-demos/AwesomeProject/node_modules/react-native/packager ~

 ┌────────────────────────────────────────────────────────────────────────────┐ 

 │  Running packager on port 8081.                                            │ 

 │                                                                            │ 

 │  Keep this packager running while developing on any JS projects. Feel      │ 

 │  free to close this tab and run your own packager instance if you          │ 

 │  prefer.                                                                   │ 

 │                                                                            │ 

 │  https://github.com/facebook/react-native                                  │ 

 │                                                                            │ 

 └────────────────────────────────────────────────────────────────────────────┘ 

Looking for JS files in

   /Users/XXX/react-native-demos/AwesomeProject 

[20:11:09] <START> Building Dependency Graph

[20:11:09] <START> Crawling File System

[Hot Module Replacement] Server listening on /hot

React packager ready.

[20:11:12] <END>   Crawling File System (2400ms)

[20:11:12] <START> Building in-memory fs for JavaScript

[20:11:12] <END>   Building in-memory fs for JavaScript (177ms)

[20:11:12] <START> Building in-memory fs for Assets

[20:11:12] <END>   Building in-memory fs for Assets (138ms)

[20:11:12] <START> Building Haste Map

[20:11:12] <START> Building (deprecated) Asset Map

[20:11:12] <END>   Building (deprecated) Asset Map (36ms)

[20:11:12] <END>   Building Haste Map (366ms)

[20:11:12] <END>   Building Dependency Graph (3087ms)

[20:11:15] <START> request:/index.ios.bundle?platform=ios&dev=true

[20:11:15] <START> find dependencies

[20:11:16] <END>   find dependencies (1416ms)

[20:11:16] <START> transform

transforming [========================================] 100% 505/505

[20:11:26] <END>   transform (9736ms)

[20:11:26] <END>   request:/index.ios.bundle?platform=ios&dev=true (11254ms)

react-native init AwesomeProject

This will walk you through creating a new React Native project in /Users/XXX/react-native-demos/AwesomeProject

Installing react-native package from npm...

Setting up new React Native app in /Users/XXX/react-native-demos/AwesomeProject

To run your app on iOS:

   cd /Users/liujunmei/react-native-demos/AwesomeProject

   react-native run-ios

   - or -

   Open /Users/liujunmei/react-native-demos/AwesomeProject/ios/AwesomeProject.xcodeproj in Xcode

   Hit the Run button

备用法:git clone https://github.com/chenxizhang/nvm.git && ./nvm/install.sh && . ~/.nvm/nvm.sh  && rm –rf ./nvm
curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash

root@i-5ygfjuik:~/iojs-v1.1.0-linux-x64# curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 5226 100 5226 0 0 4019 0 0:00:01 0:00:01 --:--:-- 4016
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
remote: Counting objects: 3328, done.
remote: Total 3328 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3328/3328), 635.28 KiB | 303.00 KiB/s, done.
Resolving deltas: 100% (1894/1894), done.
Checking connectivity... done.

=> Appending source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm

【注意:重新登录系统后才可以使用nvm

=================================================================

2、使用nvm来安装iojs
nvm install iojs

root@i-5ygfjuik:~# nvm install iojs
######################################################################## 100.0%
WARNING: checksums are currently disabled for io.js
Now using io.js v1.1.0

nvm ls 列出所有的版本

然后就用iojs就可以运行了

nvm use system
root@i-5ygfjuik:~# nvm use system
Now using system version of node: v0.11.14.
root@i-5ygfjuik:~#

这回切会11.14

root@i-5ygfjuik:~# nvm ls
    iojs-v1.1.0
-> system

root@i-5ygfjuik:~# nvm use iojs
Now using io.js v1.1.0
root@i-5ygfjuik:~#

然后再切一下就回去咯~~~~爽歪歪

=================================================================
原文地址:https://www.cnblogs.com/qiangxia/p/5243656.html