You can set up any React application using the following command-line instructions:
Instructions for Linux:
Step 1. Press Ctrl+Alt+T to open Terminal in Ubuntu.
Step 2. Check if Node.js is installed on your machine by writing the following command:
node -v
Press Enter.
If you see any version being returned to you, it means that Node.js is installed on your machine. If this version is greater than 6, you can skip steps 3 and 4 and directly jump to step 5.
If the version is not greater than 6 or if you see the message ‘Command 'node' not found, but can be installed with: sudo apt install nodejs’, which means that Node.js is not installed on your computer, close your Terminal and proceed to the next step.
Step 3. Run the following command to add Node.js-maintained repositories to your Ubuntu package source list by first downloading the scripts from deb.nodesource.com and then running them:
sudo curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
After the scripts are downloaded and run successfully, you will see something like this in your Terminal:
Step 4. Run the command given below in your Terminal to install Node.js on your machine:
sudo apt-get install -y nodejs
After Node.js has been installed on your machine, you will see something like this in your Terminal:
Step 5. Type the following command in your Terminal:
sudo npm i -g create-react-app
Press Enter.
npm stands for Node Package Manager, which gets installed while installing Node.js. i stands for install, which is a command. You can also write install in place of i. g stands for global and is preceded with a hyphen because it is a flag. create-react-app is the name of the package that you need to install. It is a CLI tool that allows you to quickly create and run React applications, with no configuration required from the user.
This command will make npm install create-react-app package globally on your machine so that you can create a React application at any valid path on your system.
Step 6. Now is the time to take one more step towards creating your first React application. In the Terminal, go to the path on your system where you want to create your application.
For example, if you want to create the application on the Desktop, go to the path in your Terminal that leads you to the Desktop.
Step 7. Create your React application using the create-react-app package that you installed on your machine in the previous step. For this, you would type a command which mentions create-react-app followed by the name of your application.
For example, here, the name of your application is phone-directory. Thus, the command can be written as follows:
create-react-app phone-directory
Press Enter.
This command will create a folder with the name that you mentioned inside your current path in the Terminal. This folder will consist of all the necessary configuration files that you need as the starter code for a React application.
Step 8. Go the application folder that you created on your current path inside the Terminal.
For example, here, the name of your application is phone-directory. Thus, you can write the following command in order to go into this application folder:
cd phone-directory
Step 9. Now you are ready to start a development server locally on your machine and run your application in development mode. For this, write the following command in your Terminal:
npm start
You can see that the development server has been started on the mentioned URL on your local machine. Here, the server has been started on the localhost with port number 3000.
This will open a browser tab/window that displays the landing page of the application, which looks something like this:
Step 10. Now, you can start making changes to your phone-directory application. Any code change that you make will get reflected immediately on the browser where the application is running.
Happy coding!