How to Setup your Mac for React Native
- Aashish Patil
- Nov 8, 2024
- 2 min read

# React Native Development Environment Setup for Mac (iOS & Android)
## Prerequisites
- macOS 10.15 or newer
- Admin access to your machine
- Terminal familiarity
## 1. Install Homebrew
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
## 2. Install Node.js & npm
```bash
brew install node
```
## 3. Install Watchman
```bash
brew install watchman
```
## 4. Install React Native CLI
```bash
npm install -g react-native-cli
```
## 5. iOS Setup
### Install Xcode
1. Download Xcode from the Mac App Store
2. Install Xcode Command Line Tools:
```bash
xcode-select --install
```
3. Install iOS Simulator:
- Open Xcode
- Go to Preferences > Locations
- Select the most recent version in Command Line Tools
### Install CocoaPods
```bash
sudo gem install cocoapods
```
## 6. Android Setup
### Install Java Development Kit (JDK)
```bash
brew tap homebrew/cask-versions
brew install --cask zulu11
```
### Install Android Studio
1. Download Android Studio from [developer.android.com](https://developer.android.com/studio)
2. During installation, ensure these components are selected:
- Android SDK
- Android SDK Platform
- Android Virtual Device
- Performance (Intel HAXM)
### Configure Android Environment Variables
Add these to your ~/.zshrc or ~/.bash_profile:
```bash
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
```
### Install Android SDK Components
1. Open Android Studio
2. Go to SDK Manager (Preferences > Appearance & Behavior > System Settings > Android SDK)
3. Select these items:
- Android SDK Platform 31 (or latest)
- Intel x86 Atom System Image
- Google APIs Intel x86 Atom System Image
- Android SDK Build-Tools
- NDK
- CMake
## 7. Create and Test a New Project
### Create Project
```bash
npx react-native init MyApp --template react-native-template-typescript
cd MyApp
```
### Run iOS
```bash
cd ios
pod install
cd ..
npx react-native run-ios
```
### Run Android
1. Start an Android emulator or connect a device
2. Run:
```bash
npx react-native run-android
```
## Troubleshooting Tips
### iOS Issues
- Clean build folder: Xcode > Product > Clean Build Folder
- Reset Metro cache:
```bash
npx react-native start --reset-cache
```
### Android Issues
- Clear gradle cache:
```bash
cd android
./gradlew clean
```
- Update gradle dependencies:
```bash
cd android
./gradlew --refresh-dependencies
```
## Recommended Development Tools
- Visual Studio Code
- React Native Debugger
- Flipper
Commentaires