ReactNative环境安装
一、Homebrew
采用 Homebrew 镜像源及工具,切换到国内。
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

选择镜像源,执行命令。
$ brew --version
Homebrew 4.1.15
二、Node
我电脑本来是Node v16 版本,但是在后续执行 npx react-native init 命令时会报错。
所以需要升级到当前比较新的版本。
官网下载安装包,或者使用命令,npm 默认也会升级。
brew install node
三、Watchman
使用 Homebrew 来安装 watchman。
brew install watchman
安装成功后,执行命令。
watchman --version
四、Ruby
Mac 默认集成了 Ruby,不过版本比较低,我的是 2.6.8,需要升级。
使用 Homebrew 安装 rbenv。
brew install rbenv ruby-build
安装完成后,运行 init 命令,根据提示,使用 echo 将 init 命令添加到 Terminal 启动前。
以保障 Terminal 启动时,rbenv 会生效。
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile: eval "$(rbenv init - bash)"
$ echo 'eval "$(rbenv init - bash)"' >> ~/.bash_profile
命令执行完成后,重启 Terminal,安装并切换到 React Native 所依赖的 Ruby 版本。
rbenv install 3.2.2
rbenv global 3.2.2
切换完成 Ruby 版本后,再次重启 Terminal,再次运行 ruby --version 命令,确定 Ruby 版本是否切换成功。
$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin21]
五、Gem 和 Bundler
切换 Ruby 包管理工具的镜像源。
切换 Gem 镜像源的方法是通过 gem sources 命令进行切换。
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.com
切换 Bundler 镜像源的方法是通过设置 config 进行切换。
bundle config mirror.https://rubygems.org https://gems.ruby-china.com
六、Xcode
安装 Xcode 有两种方法:
- 从 Mac App Store 中进行安装
- 从开发者中心进行下载和安装
在 App Store 安装时,提示我的操作系统版本过低需要升级。
所以就选择了第二种安装方式,选了个符合我当前系统的 Xcode 版本。

安装时,勾选默认选项即可。

默认项安装完成后,找到左上角的 Xcode 标识,点击 Preferences。

找到 Locations 标签中的 Command Line Tools 一栏,选择对应的 Xcode。

七、CocoaPods
CocoaPods 是另一种包管理工具,它虽然是用 Ruby 编写的,但不是 Ruby 的包管理工具,而是 iOS 的包管理工具。
借助 Gem 来安装 CocoaPods。
sudo gem install cocoapods
安装完成后,运行如下命令确定 CocoaPods 是否已经安装成功。
pod --version
遇到个奇怪的错误。
/usr/local/lib/ruby/gems/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError) deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
^^^^^^^^^^^
Did you mean? deprecate_constant
from /usr/local/lib/ruby/gems/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:8:in `<top (required)>'
from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb:9:in `<top (required)>'
from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/bin/pod:36:in `<top (required)>'
from /usr/local/bin/pod:25:in `load'
from /usr/local/bin/pod:25:in `<main>'
一顿搜索后,发现需要指定 activesupport 的版本。
sudo gem uninstall activesupport
sudo gem install activesupport --version 7.0.8
八、新建项目
使用 React Native 内建的命令行工具来创建一个名为 AwesomeProject 的新项目(记得更新 Node 版本)。
$ npx react-native@latest init AwesomeProject
Welcome to React Native!
Learn once, write anywhere
Downloading template
Copying template
Processing template
Installing Ruby Gems
Installing CocoaPods dependencies (this may take a few minutes)
error bundler: failed to load command: pod (/Users/pwstrick/code/rnative/AwesomeProject/vendor/bundle/ruby/3.2.0/bin/pod)
/Users/pwstrick/code/rnative/AwesomeProject/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError)
deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
安装的过程中,又遇到了之前的一个问题,还是在刚刚 issue 中找到了解决方案。
进入到 AwesomeProject 目录,给 Gemfile 文件增加一条命令。
gem 'activesupport', '~> 7.0.8'
然后按照步骤进行处理。
- cd iOS 打开 iOS 目录
- bundle install 安装 Bundler
- bundle update activesupport 更新支持的版本
- bundle exec pod install 安装 CocoaPods 管理的 iOS 依赖项
安装时还是会报错,无法访问 Github 中的一个仓库,跟你的网络有关,多试几次或者全局开下代理。
Downloading dependencies
Installing CocoaAsyncSocket (7.6.5)
Installing DoubleConversion (1.1.6)
Installing FBLazyVector (0.72.5)
Installing FBReactNativeSpec (0.72.5)
Installing Flipper (0.182.0)
Installing Flipper-Boost-iOSX (1.76.0.1.11) [!] Error installing Flipper-Boost-iOSX
[!] /usr/local/bin/git clone https://github.com/priteshrnandgaonkar/Flipper-Boost-iOSX.git /var/folders/6d/ly3gds1x7z160v9kqdxxdkfm0000gn/T/d20231011-86229-gl8gee --template= --single-branch --depth 1 --branch 1.76.0.1.11 Cloning into '/var/folders/6d/ly3gds1x7z160v9kqdxxdkfm0000gn/T/d20231011-86229-gl8gee'...
fatal: unable to access 'https://github.com/priteshrnandgaonkar/Flipper-Boost-iOSX.git/': LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
最后,将所有依赖安装成功。
Generating Pods project
Setting REACT_NATIVE build settings
Setting CLANG_CXX_LANGUAGE_STANDARD to c++17 on /Users/pwstrick/code/rnative/AwesomeProject/ios/AwesomeProject.xcodeproj
Pod install took 25 [s] to run
Integrating client project [!] Please close any current Xcode sessions and use `AwesomeProject.xcworkspace` for this project from now on.
Pod installation complete! There are 63 dependencies from the Podfile and 53 total pods installed. [!] Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64). [!] - Emulated x86_64 is slower than native arm64 [!] - May result in mixed architectures in rubygems (eg: ffi_c.bundle files may be x86_64 with an arm64 interpreter) [!] Run "env /usr/bin/arch -arm64 /bin/bash --login" then try again.
九、启动项目
在创建了一个名为 AwesomeProject 的新项目后,进入该项目目录,运行如下命令来启动 iOS 项目。
$ npx react-native run-ios
info Found Xcode workspace "AwesomeProject.xcworkspace"
info No booted devices or simulators found. Launching first available simulator...
info Launching iPhone SE (3rd generation) (iOS 16.0)
info Building (using "xcodebuild -workspace AwesomeProject.xcworkspace -configuration Debug -scheme AwesomeProject -destination id=5C7ACFB7-2A39-4814-8BBD-9E4ED2E1D4A4")
⠼ Building the app..
经过几分钟的编译后,在模拟器中就能得到 App 的界面,机型可自行选择。

用 VS Code 打开 AwesomeProject 目录,随意修改代码,在模拟器中可以实时看到修改的效果。
ReactNative环境安装的更多相关文章
- react-native 环境安装常见问题
npm install react-native-cli -g react-native init yourproject npm install react-native run-ios 问题1:卡 ...
- react-native学习之环境安装
1.首先是java环境安装-安装JDK 2.安装Android-SDK,推荐以下地址:http://tools.android-studio.org/index.php/sdk 然后打开SDK Man ...
- React Native 开发环境安装和配置使用报错: -bash: react-native: command not found
[React Native 开发环境安装和配置:-bash: react-native: command not found 报错: 前提是安装homebrew,node.js ,npm ,watc ...
- Mac 安装react-native 环境踩坑记
我的工程创建时间是2019.7.11号下午 :首先看一下最后我的工程的package.json各个包的版本: { "name": "MyApp", &quo ...
- react-native环境搭建
目标平台 Android 开发平台 windows 开发环境安装建议:由于开发环境存在差异,建议参照react官网 或者react中文网 安装, react-native -- 在Windows下搭建 ...
- 一步步搭建react-native环境(苹果OS X)
因重新升级了系统,一步步搭建react-native环境. 1.安装Homebrew 打开终端命令->ruby -e "$(curl -fsSL https://raw.githubu ...
- 谈谈React Native环境安装中我遇到的坑
谈谈React Native环境安装 这个坑把我困了好久,真的是接近崩溃的边缘...整理出来分享给大家,希望遇到跟我一样问题的小伙伴能尽快找到答案. 首先,这是在初始化App之后,react-nati ...
- mac上配置react-native环境run-ios/run-android命令遇到的问题
新报错(rn版本:0.53.3)2018.3.6 今天在搞react-native环境时,遇到了一些坑,这里记录一下. 首先最重要的一点是一定要按官网一步一步来,不然可能会出现一些奇奇怪怪的问题! 官 ...
- ReactNative 环境的搭建和启动(安卓版)
一.JAVA环境 下载 JDK 8.0 添加 %JAVA_HOME% 变量 添加 PATH:%JAVA_HOME%\bin 二.Android环境 下载 Android SDK 修复 SDK Mana ...
- windows 64位下,React-Native环境搭建详解 (Android)
React-Native环境搭建需要: 1.安装Java JDK 2.安装Android Studio 3.安装node.js 4.安装git 5.安装Python 2.x (注意目前不支持Pytho ...
随机推荐
- pta乙级1033(C语言)散列表解法
#include"stdio.h" #include"string.h" int main() { int flag=1; char w[100010],ch[ ...
- P9073 [WC/CTS2023] 楼梯 题解
题目链接 简要题意 有一块楼梯,这里指的楼梯是倒着的,正过来看上一层宽度一定小于等于这一层宽度,并且由格子组成,你需要对其进行增删和恢复某一历史版本的操作,并回答这块楼梯是否有固定格数的子楼梯. 题目 ...
- 如何使用Python将PDF转为Excel
PDF文件是一种静态文档格式,通常难以编辑,而Excel则是一个灵活的表格工具.如果你需要处理PDF表格中的数据,那么将其导出为Excel文件可以大大节省工作时间和精力.Excel提供的强大数据编辑和 ...
- 不要轻易定义指向std::vector中的元素的指针
类应该是被封装的,类的用户通过接口使用类提供的功能,而不必关心类的内部如何实现.然而,C++标准库容器 std::vector 的实现渗透到了接口中来.对于以下代码: const int pushNu ...
- 使用Tensorrt部署,C++ API yolov7_pose模型
使用Tensorrt部署,C++ API yolov7_pose模型 虽然标题叫部署yolov7_pose模型,但是接下来的教程可以使用Tensorrt部署任何pytorch模型. 仓库地址:http ...
- HttpClient报错Timeout waiting for connection from pool
报错现象 线上项目使用HttpClient请求第三方的HTTP资源,并发量高的时候,日志框报Timeout waiting for connection from pool 客户端的现象是有时正常,有 ...
- .net下优秀的MQTT框架MQTTnet使用方法,物联网通讯必备
MQTTnet 是一个高性能的MQTT类库,支持.NET Core和.NET Framework. MQTTnet 原理: MQTTnet 是一个用于.NET的高性能MQTT类库,实现了MQTT协议的 ...
- 路径规划算法 - 求解最短路径 - A*(A-Star)算法
Dijkstra(迪杰斯特拉)算法 A*(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法,也是解决许多搜索问题的有效算法.算法中的距离估算值与实际值越接近,最终搜索速度越快. A* ...
- 使用动画曲线编辑器打造炫酷的3D可视化ACE
前言 在制作3D可视化看板时,除了精细的模型结构外,炫酷的动画效果也是必不可少的.无论是复杂的还是简单的动画效果,要实现100%的自然平滑都是具有挑战性的工作.这涉及到物理引擎的计算和对动画效果的数学 ...
- 华企盾DSC客户端图标不显示常见处理方法
1.检查是否启用了360桌面.猎豹桌面之类的(兼容腾讯桌面),打强制显示客户端图标的补丁 2.是否被杀毒软件查杀 3.用Autoruns查看explorer项图标那一栏前10个是否有我们图标没有的话把 ...