Proceed as follows:
1. Install HomeBrew, the command is as follows:
Enter the command in the terminal: $ ruby -e " $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Verify the version of brew after waiting for the installation to succeed: $ brew -v
2. Install Nodejs
Go to https://nodejs.org/en/download/ and select the Mac version to download (node-v8.9.1.pkg) and install it.
To verify that Nodejs is installed successfully, enter the command in the terminal: $ node -v
3. Install WatchMan to detect bugs
$ brew install watchman
If you enter the above command and report as follows, follow the prompts to install the command line tools and then re-execute the command to install watchman.
To verify that watchman is installed successfully, the command is as follows: watchman -v
4. Install Flow (JavaScript's static type checker, which is convenient for finding type errors), and the command is as follows:
$ brew install flow
5. Install React Native
$ sudo npm install -g react-native-cli
6. Create a demo, cd to the target folder where the project is stored, and then execute the command:
// ReactNativeDemo is the name of the demo project
$ react-native init ReactNativeDemo
Wait for a while, when you see the following prompt message, it is successful.
To run your app on iOS: cd /Users/Jerry.Yao/Documents/My/Project/ReactNative/ReactNativeDemo react-native run-ios - or - Open ios/ReactNativeDemo.xcodeproj in Xcode Hit the Run button To run your app on Android: cd /Users/Jerry.Yao/Documents/My/Project/ReactNative/ReactNativeDemo Have an Android emulator running (quickest way to get started), or a device connected react-native run-android
7. A ReactNative demo project is generated in the target folder
[React Native development environment installation and configuration:-bash: react-native: command not found error:
The premise is that homebrew, node.js, npm, watchman, and flow are all installed successfully.
An error is reported when the react-native init TestProject command is executed to create a demo: -bash: react-native: command not found
Error message: Please include the following file with any support request: /Users/ewu/npm-debug.log, that is, the file npm-debug.log has permission,
Workaround :
Add sudo (root privileges) and execute the command:
sudo npm install -g react-native-cli
Enter the prompt to enter the computer password, press Enter again, and then create the project after success.