注:以下步骤在终端中完成
1.安装home-brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.安装node
brew install node
有可能会出现以下错误:
Error: The following directories are not writable by your user:
/usr/local/etc/bash_completion.d
/usr/local/lib/pkgconfig
/usr/local/share/info
/usr/local/share/locale
/usr/local/share/man/man3
/usr/local/share/man/man8
针对以上错误:
- 改变文件拥有者:sudo chown -R $(whoami) /usr/local
- 继续安装:brew install node
3.设置npm镜像
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
4.安装yarn, react-native-cli
npm install -g yarn react-native-cli
5.设置yarn镜像源
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
6.安装Xcode:(App Store里直接安装)
记得要在xcode->preferences->locations里把command line tools选上
7.安装Xcode命令行工具:
xcode-select —install
出现提示直接安装即可
8.安装watchman
brew install watchman
9.初始化一个项目:
react-native init AwesomeProject
10.运行
react-native run-ios
注:安装的node版本过高,可安装node指定版本
- 安装n模块:sudo npm i -g n --force
- 安装指定版本或稳定版本:n 10.0.0/stable