![]() |
VOOZH | about |
Installing React JSon a Linux system helps set up an environment for building dynamic and interactive web applications using a widely used JavaScript library.
Note: Whether youโre using Ubuntu, Fedora, or any other Linux distribution, these steps will help you get started with React development quickly and efficiently.
Before installing React JSon Linux, ensure the following requirements are met:
To get started, you need to install Node.js on your computer. When you do, npm (Node Package Manager) will usually be installed automatically because it comes with Node.js.
Note: If npm doesn't install automatically, you can download and install it separately from the npm website.
The first step in installing React JSis to ensure that Node.js is installed on your system. React JSrequires Node.js to run JavaScript on the server side and handle package management.
1. Update System Package List
sudo apt update2. Install Node.js
sudo apt install nodejs3. Installation verification
node -vnpm is the default package manager for Node.js, and it will be needed to install React JS and other dependencies.
1. Install npm
If npm is not installed with Node.js, install it manually.
sudo apt install npm2. Installation verification
You should see the version of npm installed on your system.
npm -vOnce Node.js and npm are installed, you're ready to create your first React project. The recommended tool for this is Vite, which provides a fast and optimized setup. You can also use Create React App (CRA) if required for legacy purposes.
Vite is a modern build tool that offers lightning-fast startup, minimal configuration, and a better development experience.
1. Create the project
Run the following command to scaffold a new React + JavaScript project using Vite:
npm create vite@latest my-app -- --template react2. Navigate to Project Directory and Install Dependencies
Move into your project folder and install all required dependencies:
cd my-app
npm install3. Start the Development Server
Start the development server to preview your app in the browser:
npm run devVisit http://localhost:5173 in your browser to see your React app.
Create React App was once the standard for bootstrapping React apps but has been deprecated since 2023. It's not recommended for new projects.
1. Create the project:
Run the following command to generate a new React project using CRA:
npx create-react-app my-app2. Navigate to the project directory:
Move into the newly created project folder:
cd my-app3. Starting the server:
Start the development server to launch your app:
npm startYour app will launch at http://localhost:3000 in the browser.
Note: Use lowercase for project names to avoid npm naming errors.
Once the development server is running, open your browser and go to http://localhost:3000. If everything is set up correctly, you should see the default React welcome page with a "Learn React" message. This confirms that React has been successfully installed on your Linux system.
While Create React App is the most popular way to set up a React project, there are other alternative methods available for creating a React app.
npx is a package runner tool that comes with npm. It allows you to run commands without installing them globally on your system.
npx create-react-app my-appNote: The server will start by the same command that is npm start.
Yarn is an alternative package manager to npm that is faster and more reliable in some cases. If you prefer Yarn over npm, you can follow these steps to install React.
1. Yarn Installation
To install yarn write the command in your terminal which is given below-
npm install --global yarn2. Create a new React app
yarn create react-app my-app3. Navigate to the Project Folder and Start the Development Server
cd my-app
yarn startCommon issues may occur during setup or development, but they can be resolved with proper understanding and fixes.
If you encounter the error "node: command not found" or "npm: command not found," it usually means that Node.js and npm are not installed correctly. solution is given below:-
Sometimes, when installing React or running the development server, you may encounter errors related to missing dependencies or build issues. solution is given below:-
npm installyarn installIf the React development server does not start on http://localhost:3000, you may need to check the port or firewall settings. solution for this is given below:-
lsof -i :3000