A quick guide to setting up your React Native development environment on macOS.
Prerequisites
- macOS
- Homebrew: https://brew.sh/
- Node.js (node >= 18)
- NPM
- CocoaPods
- Watchman
- JDK (Java Development Kit)
- Xcode and Simulator
- Android Studio
Setup Steps
- Install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Node.js and NVM:
brew install nvm node -v npm -v
- Install CocoaPods:
brew install cocoapods
- Install Watchman:
brew install watchman watchman -v
- Install JDK:
brew install temurin17 java -version
- Install Xcode from the App Store and set up the simulator.
- Install Android Studio and required SDKs.
Create a New React Native Project
npx @react-native-community/cli init MyReactNativeFirst
cd MyReactNativeFirst
npm install
Run the Project
- For Android:
react-native run-android
- For iOS:
react-native run-ios
Environment Variables
Add the following to your ~/.zshrc
:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$PATH
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/your-version
export PATH=$ANDROID_NDK_HOME:$PATH
export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"
Troubleshooting
- Run
npx react-native doctor
to diagnose issues. - Run
npx react-native info
for environment info.
Happy coding!