let’s see how to install and configure react-native development environment on Mac. If you want to know how to install react-native on Windows, see the blog post below.
you can use
Expo CLI and
React Native CLI to develop react-native app on Mac.
Expo CLI is the package includes many native features(geolocation, camera, etc) when you develop the app with react-native. At the first time, when you develop the react native with Expo CLI, you can feel easy and comfortable. However, this pacakge includes many native features those you don’t use, and that makes the app build size bigger. Also, if you want to integrate the native feature which Expo CLI doesn’t include, it’s hard to make it. Therefore, this blog post doesn’t recommend to use Expo CLI.
This blog post is about how to install and configure React Native CLI environment. Also, we’ll create react-native project by React Native CLI and check it works well.
We need to install Nodejs, Watchman, Xcode, etc to develop the app by react-native. let’s see how to install them one by one.
Homebrew is a package manager on Mac to install and manage packages. We can install packages simply on Mac via Homebrew.
- Homebrew: https://brew.sh/
First, execute the command below to check Homebrew is installed on Mac.
If Homebrew is installed, you can see Homebrew version like below.
homebrew 2.1.7 homebrew/homebrew-core (git revision f487; last commit 2019-07-20)
If Homebrew version is not shown, you can install Homebrew via the command below.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After installing, execute the command below to check Homebrew is installed well.
If Homebrew is installed well, you can see Homebrew version like below.
homebrew 2.1.7 homebrew/homebrew-core (git revision f487; last commit 2019-07-20)
- Nodejs: https://nodejs.org/
execute Homebrew command below to install Nodejs.
brew install node
After installing, execute the command below to check Nodejs is installed well.
If Nodejs is installed well, you can see Nodejs version on the screen.
When Nodejs is installed, basically, npm (Node Package Manager) is also installed. Execute the command below to check npm is installed well.
If npm is installed well, you can see npm version like below.
Watchman is to watch specific folders or files, and if they is changed, Watchman can trigger some actions. In react-native, Watchman watches the source codes and if they are added or changed, Watchman rebuilds them.
- Watchman: https://facebook.github.io/watchman/
Execute Homebrew command below to install Watchman.
brew install watchman
After installing, execute the command below to check Watchman is installed well.
If Watchman is installed well, Watchman version would be shown up.
React Native CLI
Let’s install React Native CLI to develop the app by react-native. Execute npm command below to install React Native CLI globally.
npm install -g react-native-cli
After installing, execute the command below to check React Native CLI is installed well.
npx react-native --version
If React Native CLI is installed well, you can see React Native CLI version like below.
react-native-cli: 2.0.1 react-native: n/a - not inside a React Native project
We need Xcode to develop iOS app by react-native. Click the link below to install Xcode via App store.
- Xcode download link: https://apps.apple.com/us/app/xcode/id497799835?mt=12
After Xcode is installed, we need to configure Command Line Tools. Execute Xcode and click
Xcode > Preferences... > Locations on the top menu. When you click it, you can see Command Line Tools setting like below.
If the setting is not like above, click the dropdown menu and select last version of Command Line Tool.
Cocoapods is the dependency manager on iOS development.
- Cocoapods: https://cocoapods.org/
Cocoapods is necessary to develop an app by react-native. Execute the command below to install Cocoapods.
sudo gem install cocoapods
After installing, execute the command below to check Cocoapods is installed well.
If Cocoapods is installed well, you can see Cocoapods version like below.
We need to install JDK(Java Development Kit) to develop Android app with react-native. Execute the command below to install JDK.
brew tap AdoptOpenJDK/openjdk brew cask install adoptopenjdk8
After installing, Execute the command below to check Java is installed well.
If Java is installed well via installing JDK, you can see Java version like below.
openjdk version "1.8.0_222" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode)
When JDK is installed, Java compiler is alo installed. Execute the command below to check Java compiler is also installed well.
If Java compiler is installed well via installing JDK, Java compiler version is shown up like below.
We need to install Android Studio to develop Android app with react-native. Click the link below to go to Android Studio site and download the installation file.
- Android Studio: https://developer.android.com/studio
After downloading, execute the installation file to execute Android Studio.
Android Studio Configuration
you can see the screen like below after executing Android Studio.
Click Next button to go to next screen. When you go to the next screen, you can see Install Type configuration screen. Select Custom option and click next button to go to next screen.
When you go to the next screen, you can see Select UI Theme screen like below. Select the theme which you like, and click Next button to go to the next screen.
When you go to the next screen, you can see SDK Components Setup screen like below. Select
Performance (Intel ® HAXM) option and
Android Virtual Device option, and clic Next button.
on the next screen, you can see Emulator Settings screen like below. Click Next button without any changing especially.
the next process is just normal program installation, so I don’t explain the detail. Just click Finish button to continue Android studio installation to complete it.
After Android studio installation, you can see Android studio is executed like below.
Android Studio SDK Configuration
Configure > SDK Manger menu on the right botton to go to Android SDK configuration.
When the screen is shown up like below, select
Show Pacakge Details option on the right bottom. find and select the options below on the list.
- Android SDK Platform 29
- Intel x86 Atom System Image
- Google APIs Intel x86 Atom System Image
- Google APIs Intel x86 Atom_64 System Image
If you select all options above, click OK button on the right bottom to install them.
Configure Android Studio Environment Variable
Android studio installation and configuration are done. Now, we need to set the environment variables. open
~/.bash_profile file or
~/.zshrc file and add the code below to them to add the environment variables.
# export ANDROID_HOME=$HOME/Library/Android/sdk export ANDROID_HOME=Android SDK directory location/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools
If you use
.bash_profile, execute the command below.
source ~/.bash_profile # or source ~/.zshrc
on the code above, you should modify Android SDK directory location to your location. If you don’t know where your Android SDK location, go to the Android Studio SDK configuration.
you can find your Android SDK directory location at Android SDK Location section on the top of the Android studio SDK configuration screen.
After configuration, re-start the terminal and execute the command below.
If the environment variables are configured well, you can see the result like below.
Android Debug Bridge version 1.0.41 Version 29.0.1-5644136 Installed as /Your Android SDK Directory Location/platform-tools/adb
Create & Check react-native Project
Execute React Native CLI command below to create react-native project.
npx react-native init SampleApp
Check on iOS
After creating, execute the command below to execute the react-native app on iOS.
cd SampleApp # react-native run-ios npm run ios
If you can’t execute well, execute
ios/SampleApp.xcworkspace file and select the simulator on the top of Xcode screen, and click the arrow button to execute the simulator.
If the react-native app is executed well, you can see the screen like below.
Check on Android
In Android, execute the command below after connecting the device that the developer mode is activated via USB or executing Android studio emulator.
cd SampleApp # react-native run-android npm run android
If you don’t have any problen, you can see the screen like below.
We’ve seen how to install and configure react-native to develop the app on Mac. Also, We’ve created the app by React Native CLI and executed it to check the environment is configured well.
Now, we are ready to develop the app with react-native. Let’s dive to the react-native development world!
Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!
Deku. 지금 보고 계신 블로그를 작성하는
Deku가 개발한 앱을 한번 사용해보세요.
Dekucreated the applications with Flutter.
If you have interested, please try to download them for free.