How to Install React: A Step-by-Step Setup Guide for Web Developers
React is one of the most widely used JavaScript libraries for building user interfaces — but before you write your first component, you need to get it installed and running correctly. The process is straightforward once you understand what's actually happening under the hood, and knowing that makes troubleshooting much easier if something goes sideways.
What React Installation Actually Involves
React itself is a JavaScript library, which means it doesn't install like a desktop app. Instead, you pull it into a project using a package manager — typically npm (Node Package Manager) or yarn. These tools download React and its dependencies from an online registry and wire them into your project.
Before React can be installed, your machine needs Node.js — a JavaScript runtime that makes npm available. React doesn't run inside Node.js directly, but the tooling around it does.
Step 1: Install Node.js and npm
Go to nodejs.org and download the LTS (Long-Term Support) version. This is the stable release recommended for most users. The installer includes npm automatically.
To confirm the installation worked, open your terminal or command prompt and run:
node -v npm -v Both commands should return a version number. If they do, you're ready to move forward.
Node version matters. React's official tooling generally requires Node 14 or higher, though more recent tooling (like Vite) works best with Node 16+. If you're on an older machine or a managed system, check your Node version before assuming things will work out of the box.
Step 2: Choose Your Setup Method
This is where individual setups start to diverge. There are a few common approaches, and the right one depends on your project type and experience level.
Option A: Create React App (CRA)
Create React App is the long-standing official scaffolding tool. It sets up a complete project structure with a development server, build pipeline, and testing configuration — no manual config required.
npx create-react-app my-app cd my-app npm start npx runs the tool without permanently installing it. The npm start command launches a local development server, typically at http://localhost:3000.
Who it suits: Beginners and developers who want a batteries-included setup with no webpack configuration to manage.
Worth knowing: Create React App has slowed in active development, and some in the community consider it heavier than necessary for modern projects. It's still functional and widely documented, but it's no longer the only recommended starting point.
Option B: Vite
Vite has become a popular alternative for React projects. It's faster to start, leaner in output, and actively maintained.
npm create vite@latest my-app -- --template react cd my-app npm install npm run dev The development server runs noticeably faster than CRA, especially as projects grow. Vite uses ES modules natively, which changes how imports and hot reloading work compared to older bundlers.
Who it suits: Developers comfortable with a slightly more hands-on setup who want better performance and a modern toolchain.
Option C: Manual Installation (React Without a Scaffold)
You can add React to an existing project or a bare HTML file without any scaffolding tool. This means installing React and ReactDOM directly:
npm install react react-dom You'll also need a bundler (like Webpack or Vite) and a transpiler (like Babel) configured manually to handle JSX and modern JavaScript syntax. This approach gives maximum control but requires significantly more configuration.
Who it suits: Developers integrating React into an existing codebase, or those who want to understand exactly what each piece of the toolchain does.
Step 3: Understand the Key Files 🗂️
Regardless of setup method, a React project has a consistent core structure:
| File/Folder | Purpose |
|---|---|
src/ | Where your React components and logic live |
public/ | Static assets served directly (HTML template, favicon) |
index.js or main.jsx | Entry point — mounts React into the DOM |
package.json | Tracks dependencies and scripts |
node_modules/ | All installed packages (don't edit manually) |
The index.js file (or main.jsx in Vite) is where React connects to your HTML page via a <div id="root"> element. Everything React renders flows through that mount point.
Common Installation Issues
"npm is not recognized" — Node.js didn't install correctly, or your system PATH wasn't updated. Reinstalling Node usually resolves this.
Permission errors on Mac/Linux — Using sudo with npm is generally discouraged. Instead, configure npm to use a directory you own, or use a version manager like nvm (Node Version Manager) to avoid permission conflicts entirely.
Slow installs or registry timeouts — This is usually a network issue. Switching to yarn or setting a different npm registry can help in some regions.
JSX errors in plain JavaScript files — If you're using Vite with .js extensions instead of .jsx, you may need to configure the JSX transform explicitly. This is a common gotcha when switching between tools.
The Variables That Shape Your Experience 🔧
Installation goes smoothly for most people — but the experience varies depending on a few real factors:
- Operating system: Windows, macOS, and Linux each have slightly different terminal behaviors, permission models, and PATH configurations.
- Node version: Using an outdated Node version can cause silent failures or cryptic errors with newer tooling.
- Existing project context: Adding React to a legacy codebase with its own build system is a different problem than starting fresh.
- Toolchain familiarity: If you've never used a terminal or npm before, the scaffolded tools (CRA, Vite) remove a lot of friction. If you're migrating from another framework, manual setup might integrate more cleanly.
- Team or org constraints: Some development environments restrict what can be installed globally, which affects whether
npxor global installs are even an option.
The mechanics of installing React are consistent — Node, npm, a setup command, and a running dev server. But how that plays out, and which setup path makes sense, shifts considerably depending on what you're building and the environment you're building in.