mac搭建react-native开发环境记录

首先安装Homebrew

什么是Homebrew呢?Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X. 官方的解释非常明了,Homebrew是一个包管理器,用于在Mac上安装一些OS X没有的UNIX工具(比如著名的wget),能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就是mac下的apt-get、yum神器。

Brew安装方法很多种,我用一种终极方法一键就搞定

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

如果这种方法你搞不定你自己看看其他安装的方法。

安装了Homebrew后,我们安装node

安装node

brew install node

好像是可以指定版本的 (这样:brew install node@14.17.5)你自己试试。

由于这样安装太慢,我等不了,我的node实际是 下载pkg ,然后运行安装的,下载地址:

https://nodejs.org/download/release/v14.17.5/

安装Watchman

brew install watchman

安装Cocoapods

brew install cocoapods

实际我没有用这个方法安装cocoapods,我是使用gem安装的

gem sources -l

gem source -r https://rubygems.org/

gem source -a https://gems.ruby-china.com/

sudo gem install cocoapods

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git  ~/.cocoapods/repos/trunk

验证 pod是否可用

pod --version

安装react-native-cli

npm install react-native-cli -g

发现安装目录没有权限,然后我chmod -R 777 /dir给目录授权可写权限后安装react-native-cli成功了

但是我在 init react native项目时候cocoapods出错了。

后来这么解决:

pod repo 换源

gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

pod repo

cd ~/.cocoapods/repos

pod repo remove master

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

然后进入react native 目录中ios目录

pod install

这样正常安装了,但是碰到“Installing glog (0.3.5) 安装报错”

在RN项目根目录:

sudo xcode-select --switch /Applications/Xcode.app
cd ios && pod install

这样就解决了这个问题

然后

npm run ios,就开始启动模拟器,开始编译自动安装了。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值