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 ...
随机推荐
- ssr服务器极致渲染
域名 RDS 云服务器 ECS 中国站 文档购物车ICP备案控制台 金秋上云季 首页 技术与产品 社区 直播 开发者学堂 开发者云 工具与资源中心 天池大赛 飞 ...
- docker入门加实战——docker安装并配置阿里云加速
docker入门加实战--docker安装并配置阿里云加速 为什么要学习docker 在开发和部署项目的过程中,经常会遇到如下问题: 软件安装包名字复杂,不知道去哪里找 安装软件和部署项目步骤复杂,容 ...
- MongoDB 中的索引分析
MongoDB 的索引 前言 MongoDB 使用 B 树还是 B+ 树索引 单键索引 创建单键索引 使用 expireAfterSeconds 创建 TTL 索引 复合索引 最左匹配原则 ESR 规 ...
- struct 结构体【GO 基础】
〇.前言 虽然 Go 语言中没有"类"的概念,也不支持"类"的继承等面向对象的概念,但是可以通过结构体的内嵌,再配合接口,来实现面向对象,甚至具有更高的扩展性和 ...
- .then()方法的意思和用法
then()方法是异步执行. 意思是:就是当.then()前的方法执行完后再执行then()内部的程序,这样就避免了,数据没获取到等的问题. 语法:promise.then(onCompleted, ...
- 手把手教你在项目中引入Excel报表组件
摘要:本文由葡萄城技术团队原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 GrapeCity Documents for Excel(以下 ...
- 如何使用DALL-E 3
如何使用 DALL-E 3:OpenAI 图像生成指南 DALL-E 3 是 OpenAI 图像生成器的高级版本,它可以理解自然语言提示来创建详细图像. 它克服了以前版本的方形图像限制,现在支持各种宽 ...
- js前端操作,c#后端下发xml文件
前端: var xmlLanguageDoc; $.ajax({ url: "/GiveMeXML",//此处可随意定义,不一定是路径.在c# ,请求被捕获后,由c ...
- umich cv-5-1 神经网络训练1
这节课中介绍了训练神经网络的第一部分,包括激活函数的选择,权重初始化,数据预处理以及正则化方法 训练神经网络1 激活函数 数据预处理 权重初始化 正则化方法 激活函数 这部分主要讨论我们之前提到的几种 ...
- meet
以后就放弃csdn了,就来这里记录自己的成长,就当成一个树洞吧,开心与难过,学习与生活,进步与成长,留下时间的痕迹!冲!冲!冲!