How to Install React Native: Step-by-Step Guide
To install
React Native, first install Node.js, then create a new project with npx react-native init ProjectName. Next, set up your development environment by installing Android Studio or Xcode depending on your platform, then run your app using npx react-native run-android or npx react-native run-ios.Syntax
Here is the basic syntax to install React Native and create a new project:
npx react-native init ProjectName: Creates a new React Native project namedProjectName.- Use
npx react-native run-androidornpx react-native run-iosto run the app on Android or iOS simulators.
bash
npx react-native init ProjectName cd ProjectName npx react-native run-android # or run-ios
Example
This example shows how to create and run a new React Native app on Android:
bash
npx react-native init MyApp cd MyApp npx react-native run-android
Output
Starting Metro Bundler...
Building and installing the app on Android emulator...
App launched successfully on the emulator.
Common Pitfalls
Common mistakes when installing React Native include:
- Not installing
Node.jsfirst, which is required. - Skipping Android Studio or Xcode setup, causing build errors.
- Using
react-native initwithoutnpxwhich may cause version conflicts. - Not setting up environment variables like
ANDROID_HOMEon Windows or macOS.
bash
Wrong: npm install react-native-cli react-native init MyApp Right: npx react-native init MyApp
Quick Reference
Summary tips for installing React Native:
- Always install
Node.jsfirst. - Use
npx react-native initto create projects. - Set up Android Studio for Android or Xcode for iOS development.
- Run your app with
npx react-native run-androidornpx react-native run-ios.
Key Takeaways
Install Node.js before installing React Native CLI.
Use npx to create new React Native projects to avoid version issues.
Set up Android Studio or Xcode depending on your target platform.
Run your app on an emulator or device using React Native CLI commands.
Check environment variables and dependencies to prevent build errors.