Install Reactjs on Ubuntu
Learn to install ReactJS on Ubuntu and create a sample React application in this quick tutorial.
Developed by Facebook, React is one of the most popular front-end JavaScript libraries that is used by tech giants like Netflix, Twitter, Facebook, and many more.
And in this tutorial, you will learn the following:
- How to install ReactJS on Ubuntu
- How to install and use
create-react-app
to create react an application
Let's see how to do it.
How to install ReactJS on Ubuntu
To install react, you must install npm first, which is available from the universe repository.
So if you haven't added the universe repository, you can refer to our detailed guide on how to add the universe and multiverse repository on Ubuntu.
Once you have enabled the universe repository, use the following command to install react:
sudo apt install npm
To confirm the installation, you can check the installed version of npm using the following command:
npm --version
And to check the node version, you can use the following command:
node --version
That's a pretty old version and it won't work with the create-react-app utility.
So let's update the Node to the latest version.
Update Node to the latest version
To update the node, all you need is a tool named n
which can be installed with the npm:
npm install -g n
And finally, install the latest LTS release of Node (18.14.2 while writing):
sudo n lts
Now, log out and log back in and check the node version:
How to install the create-react-app utility
If you don't know, the create-react-app utility avails you of every necessary tool that is used to create a react application.
Unlike the previous installation, you will have to use the npm package manager to install this package:
sudo npm -g install create-react-app
Once you are done with the installation, check the installed version:
create-react-app --version
How to create React application on Ubuntu
In this section, I will walk you through how you can create a sample react application from the installation you've made previously.
To create a react application, all you have to do is append the desired name of the application to the create-react-app
command:
create-react-app [Name_your_application]
For example, here, I created a sample application named learnubuntu
:
create-react-app learnubuntu
It will take a couple of minutes and if things go smoothly, you will get the following message after the successful installation of your application:
To run this application, first, you will have to change your directory to the application:
cd [application_name]
And finally, start the application using the following command:
npm start
Now, you can use any of your preferred browsers to check the application by using the given link.
And it will show you something like this:
There you have it!
Feel free to 'react' to this article in the comment section.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.