Setting up a React Native development environment can be tricky, especially for iOS development. This module provides step-by-step instructions for all platforms and both Expo and React Native CLI workflows.What You’ll Learn:
Before setting up, choose your development approach:
Copy
┌─────────────────────────────────────────────────────────────────────────────┐│ Expo vs React Native CLI │├─────────────────────────────────────────────────────────────────────────────┤│ ││ Expo (Recommended for Most Projects) ││ ──────────────────────────────────── ││ ✅ Zero native code configuration ││ ✅ Expo Go app for instant testing ││ ✅ EAS Build for cloud builds ││ ✅ Over-the-air updates ││ ✅ Pre-built native modules ││ ✅ Works on Windows/Linux for iOS (via EAS) ││ ⚠️ Some native modules require "development builds" ││ ││ React Native CLI (Bare Workflow) ││ ──────────────────────────────── ││ ✅ Full native code access ││ ✅ Any native module/SDK ││ ✅ Custom native code ││ ⚠️ Requires Xcode (macOS) for iOS ││ ⚠️ More complex setup ││ ⚠️ Manual native configuration ││ ││ Recommendation: ││ Start with Expo. Use "development builds" when you need custom ││ native code. You get the best of both worlds. ││ │└─────────────────────────────────────────────────────────────────────────────┘
# Using Homebrew (recommended)brew install node# Or using nvm (Node Version Manager)curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashsource ~/.zshrc # or ~/.bashrcnvm install 20nvm use 20nvm alias default 20# Verify installationnode --version # Should be v18.x or highernpm --version # Should be v9.x or higher
Copy
# Option 1: Download installer from nodejs.org# https://nodejs.org/en/download/# Option 2: Using Chocolateychoco install nodejs-lts# Option 3: Using nvm-windows# Download from: https://github.com/coreybutler/nvm-windows/releasesnvm install 20nvm use 20# Verify installationnode --versionnpm --version
Copy
# Using nvm (recommended)curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashsource ~/.bashrcnvm install 20nvm use 20nvm alias default 20# Or using NodeSourcecurl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -sudo apt-get install -y nodejs# Verify installationnode --versionnpm --version
# Start the development servernpx expo start# Options in the terminal:# Press 'i' - Open iOS simulator (macOS only)# Press 'a' - Open Android emulator# Press 'w' - Open in web browser# Press 'r' - Reload app# Press 'm' - Toggle menu# Press 'j' - Open debugger# Or scan the QR code with:# - iOS: Camera app# - Android: Expo Go app
# Install from Mac App Store (recommended)# Search for "Xcode" in App Store# Or install via command linexcode-select --install# After installation, open Xcode and accept the licensesudo xcodebuild -license accept# Install additional components when prompted
# Install command line toolsxcode-select --install# Verify installationxcode-select -p# Should output: /Applications/Xcode.app/Contents/Developer# If you have multiple Xcode versionssudo xcode-select --switch /Applications/Xcode.app
# Open Xcodeopen -a Xcode# Go to: Xcode → Settings → Platforms# Click '+' and install iOS simulators# Or via command linexcodebuild -downloadPlatform iOS# List available simulatorsxcrun simctl list devices
# Create a test projectnpx react-native@latest init TestProjectcd TestProject# Run on iOS simulatornpx react-native run-ios# Or with Exponpx create-expo-app@latest test-expocd test-exponpx expo run:ios
# Using Homebrewbrew install openjdk@17# Add to PATH (add to ~/.zshrc or ~/.bashrc)export JAVA_HOME=$(/usr/libexec/java_home -v 17)export PATH=$JAVA_HOME/bin:$PATH# Verifyjava -version
Copy
# Download from Microsoft# https://learn.microsoft.com/en-us/java/openjdk/download# Or using Chocolateychoco install microsoft-openjdk17# Set JAVA_HOME environment variable# System Properties → Environment Variables → New# Variable: JAVA_HOME# Value: C:\Program Files\Microsoft\jdk-17.x.x# Verifyjava -version
Copy
# Ubuntu/Debiansudo apt install openjdk-17-jdk# Fedorasudo dnf install java-17-openjdk-devel# Set JAVA_HOME (add to ~/.bashrc)export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64export PATH=$JAVA_HOME/bin:$PATH# Verifyjava -version
# Open Android Studio# Go to: More Actions → Virtual Device Manager# Click "Create Device"# 1. Select hardware: Pixel 7 (or similar)# 2. Select system image: API 34 (download if needed)# 3. Name your AVD and finish# Or via command line# List available system imagessdkmanager --list | grep system-images# Download system imagesdkmanager "system-images;android-34;google_apis;x86_64"# Create AVDavdmanager create avd -n Pixel_7_API_34 -k "system-images;android-34;google_apis;x86_64" -d "pixel_7"# List AVDsemulator -list-avds# Start emulatoremulator -avd Pixel_7_API_34
Hardware acceleration is enabled by default on macOS with Apple Silicon or Intel HAXM.
Copy
# Enable Hyper-V (Windows 10/11 Pro)# Open PowerShell as AdministratorEnable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All# Or enable Windows Hypervisor PlatformEnable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All# Restart computer# For AMD processors, enable SVM in BIOS# For Intel processors, enable VT-x in BIOS
Copy
# Install KVMsudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils# Add user to kvm groupsudo adduser $USER kvm# Verify KVMkvm-ok# Logout and login for group changes
# 1. Connect iPhone via USB# 2. Trust the computer on your iPhone# 3. Open Xcode → Window → Devices and Simulators# 4. Select your device and enable "Connect via network" (optional)# For development builds# 1. Sign in with Apple ID in Xcode# 2. Select your team in project settings# 3. Enable "Automatically manage signing"# Run on devicenpx react-native run-ios --device "Your iPhone Name"# Or with Exponpx expo run:ios --device
# 1. Enable Developer Options on your Android device# Settings → About Phone → Tap "Build Number" 7 times# 2. Enable USB Debugging# Settings → Developer Options → USB Debugging → Enable# 3. Connect via USB and accept the debugging prompt# 4. Verify device is connectedadb devices# Should show your device# Run on devicenpx react-native run-android# Or with Exponpx expo run:android --device
# Create local.properties in android folderecho "sdk.dir=$ANDROID_HOME" > android/local.properties# Or on Windowsecho sdk.dir=C:\\Users\\YOUR_USERNAME\\AppData\\Local\\Android\\Sdk > android\local.properties
Android: 'INSTALL_FAILED_INSUFFICIENT_STORAGE'
Copy
# Clear emulator dataemulator -avd YOUR_AVD_NAME -wipe-data# Or increase emulator storage in AVD settings
Metro bundler port in use
Copy
# Kill process on port 8081# macOS/Linuxlsof -i :8081 | grep LISTEN | awk '{print $2}' | xargs kill -9# Windowsnetstat -ano | findstr :8081taskkill /PID <PID> /F# Or use different portnpx react-native start --port 8082
# 1. Open project in Xcodeopen ios/YourProject.xcworkspace# 2. Select your project in navigator# 3. Go to Signing & Capabilities# 4. Select your Team# 5. Enable "Automatically manage signing"# 6. Change Bundle Identifier if needed