0
0
React-nativeHow-ToBeginner ยท 3 min read

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 install or yarn: 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:

  1. Open a terminal in your project folder.
  2. Run npm install to install dependencies.
  3. Start the Metro bundler with npx react-native start.
  4. Open another terminal and run npx react-native run-android.
  5. 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

CommandPurpose
npm install or yarnInstall project dependencies
npx react-native startStart Metro bundler
npx react-native run-androidRun app on Android device/emulator
npx react-native run-iosRun 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.