How to Run React Native App: Step-by-Step Guide
To run a React Native app, first install dependencies with
npm install or yarn. Then start the Metro bundler using npx react-native start and run the app on Android with npx react-native run-android or on iOS with npx react-native run-ios.Syntax
Here are the main commands to run a React Native app:
npm installoryarn: Installs project dependencies.npx react-native start: Starts the Metro bundler, which serves your JavaScript code.npx react-native run-android: Builds and runs the app on an Android device or emulator.npx react-native run-ios: Builds and runs the app on an iOS simulator (macOS only).
Make sure you have an Android emulator or iOS simulator running, or a physical device connected.
bash
npm install npx react-native start npx react-native run-android # or npx react-native run-ios
Example
This example shows how to run a simple React Native app on Android:
- Open a terminal in your project folder.
- Run
npm installto install dependencies. - Start the Metro bundler with
npx react-native start. - Open another terminal and run
npx react-native run-android. - The app will build and launch on your connected Android device or emulator.
javascript
import React from 'react'; import { Text, View } from 'react-native'; export default function App() { return ( <View style={{flex:1, justifyContent:'center', alignItems:'center'}}> <Text>Hello, React Native!</Text> </View> ); }
Output
A mobile screen with centered text: "Hello, React Native!"
Common Pitfalls
Common mistakes when running React Native apps include:
- Not starting the Metro bundler before running the app.
- Trying to run iOS commands on non-macOS systems.
- Not having an emulator or device connected.
- Missing Android SDK or Xcode setup.
- Using outdated React Native CLI commands.
Always check your environment setup and device connections before running.
bash
Wrong: npx react-native run-ios # on Windows or Linux Right: # Use Android commands on Windows/Linux npx react-native run-android # Use iOS commands only on macOS npx react-native run-ios
Quick Reference
| Command | Purpose |
|---|---|
| npm install or yarn | Install project dependencies |
| npx react-native start | Start Metro bundler |
| npx react-native run-android | Run app on Android device/emulator |
| npx react-native run-ios | Run app on iOS simulator (macOS only) |
Key Takeaways
Always install dependencies before running your React Native app.
Start the Metro bundler with 'npx react-native start' before launching the app.
Use 'npx react-native run-android' for Android and 'npx react-native run-ios' for iOS (macOS only).
Ensure your device or emulator/simulator is running and connected.
Avoid running iOS commands on non-macOS systems to prevent errors.