【React-Native】开发环境搭建 Mac M2

【React-Native】开发环境搭建 Mac M2

    • 一、Node & Watchman & yarn
      • 1. 安装brew
      • 2. 安装Node & Watchman & yarn
    • 二、IOS
      • 1. Ruby & rbenv
      • 2. Xcode & Command Line Tools & CocoaPods
    • 三、Android
      • 1.Java Development Kit
      • 2.Android Studio & Android SDK
      • 3.配置环境变量
    • 四、检查环境
    • 五、创建项目 & 编译运行

一、Node & Watchman & yarn

1. 安装brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. 安装Node & Watchman & yarn

brew install node
brew install watchman
npm install -g yarn

二、IOS

1. Ruby & rbenv

ruby --version //检查ruby版本
brew install rbenv ruby-build //安装rbuy版本管理工具rbenv


$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.zshrc:

eval "$(rbenv init - zsh)"

rbenv install  2.7.6 //安装指定版本
rbenv global 2.7.6	//设置ruby版本

2. Xcode & Command Line Tools & CocoaPods

Xcode 直接到 App Store下载安装即可

需要注意的是 检查 Xcode > Preferences > Locations 的Command Line Tools是否安装成功

brew install cocoapods //安装cocoapods

三、Android

1.Java Development Kit

brew tap homebrew/cask-versions
brew install --cask zulu11

2.Android Studio & Android SDK

1、下载 https://developer.android.google.cn/studio/ 

2、配置SDK Platform & SDK Tools
Android Studio > Preferences > Appearance & Behavior > System Settings > Android SDK

有两个选项卡 SDK Platform 和 SDK Tools 选择版本需要的安装即可

3.配置环境变量

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

四、检查环境

$ npx @react-native-community/cli doctor
Common
 ✓ Node.js
 ✓ yarn
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI
 ✓ .xcode.env - File to customize Xcode environment

Errors:   0
Warnings: 0

五、创建项目 & 编译运行

npx react-native init xxx //xxx项目名称

//编译运行
yarn android
yarn ios

你可能感兴趣的:(macos,react,native,ruby)