How to Install React on Ubuntu 26.04 and 24.04

Share

To install React on Ubuntu 26.04 or 24.04, create a React project with Vite and install its dependencies with npm. React is a JavaScript library for building interactive interfaces; Vite supplies the local development server and build tools.

React belongs to each project, not to Ubuntu as a system-wide application. Follow the steps below to set up Node.js, run a starter app and make a production build. If you need help, leave a comment or contact us.

Before you begin
  • Ubuntu 26.04 or 24.04, a terminal, internet access and a browser.
  • A regular user account and sudo access for the Node setup prerequisites.
  • A supported Node.js LTS release and npm. Check the versions before creating the project.
  • Use a new project directory. Do not overwrite an existing app.
Ubuntu 26.04 & 24.04

From terminal to React app

Install the tools, start a local server and build your first project.

1. Set Up Node.js and npm

Node.js runs the development tools, and npm installs the packages they need. If you already have both, check them first:

Terminal
node --version
npm --version
command -v node
command -v npm

Vite currently requires Node.js 20.19+ or 22.12+, and individual templates can require more. Node 20 has reached upstream end of life, so choose a supported LTS release that meets the current Vite requirements. Node.js 26 and 24 are LTS as of November 2026. Ubuntu 24.04’s default Node.js 18 package is too old for current Vite. If your existing version is compatible, skip to the project section.

For a new development setup, nvm installs Node.js for your user and lets you switch versions without replacing system packages. The full Node.js installation guide also covers Ubuntu packages and managing versions.

1   Install prerequisites

Refresh package lists and install the tools and library used by the current Node binaries. Stop if APT reports an error.

Terminal
sudo apt update
sudo apt install curl ca-certificates libatomic1
2   Download and review nvm

This downloads the official nvm installer to a temporary file and opens it for review. It installs software for your user and modifies a shell profile. Press q to leave the viewer.

Terminal
nvm_installer=$(mktemp) && curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh -o "$nvm_installer" && less "$nvm_installer"

Only after a successful download and review, run the installer as your normal user, then remove the temporary file in the same terminal:

Terminal
bash "$nvm_installer"

After a successful install:

Terminal
rm -- "$nvm_installer"

Open a new terminal to load nvm. Do not use sudo with nvm.

3   Install an LTS release

The first command should print nvm. If it does not, stop and reopen the terminal or consult the Node.js guide. Then install the current LTS version and verify it:

Terminal
command -v nvm
nvm install --lts
node --version
npm --version

Check the reported Node version against Vite’s requirements. If an existing project requires a particular version, select that version instead of changing it blindly.

2. Create a React Project

1   Create a new folder from the React template

From your home directory, create a project named react-demo. Choose another unused name if that folder already exists. If npm asks to install create-vite, confirm after checking the prompt.

Terminal
cd ~
npm create vite@latest react-demo -- --template react

Follow any remaining prompts. The command creates starter files; it does not yet install the project dependencies.

2   Install the dependencies

Enter the new directory only after the scaffold succeeds, then install its packages:

Terminal
cd ~/react-demo && npm install

The template lists React and React DOM in package.json. npm places installed packages in node_modules and creates a lockfile. Keep package-lock.json with the project so installs can be reproduced. Do not use sudo for these commands.

3   Start the development server

Run this inside react-demo:

Terminal
npm run dev

Open the local address printed by Vite, usually http://localhost:5173/, in a browser on the same computer. If the port is busy, use the different address printed in your terminal. The React starter page should appear. Press Ctrl+C in the terminal to stop the server.

The default local address is for your own computer. Do not expose the development server to a public network.

3. Edit and Verify Your App

Open ~/react-demo/src/App.jsx in a text editor, such as Visual Studio Code. Replace its contents with this small component and save it:

App.jsx
export default function App() {
  return <h1>Hello from Ubuntu!</h1>
}

With the development server running, the browser should update and show Hello from Ubuntu! The file contains JSX, a syntax that lets React describe what appears on the page. If you stopped the server, return to the project directory and run npm run dev again.

To check the installed React packages, open a second terminal and run the commands below. Alternatively, stop the development server with Ctrl+C and use the same terminal.

Terminal
cd ~/react-demo && npm ls react react-dom

4. Build for Production

Stop the development server with Ctrl+C, then build and preview the optimized files locally:

Terminal
npm run build && npm run preview

A successful build writes static files to dist/. Open the local address printed by the preview command, then press Ctrl+C to stop it. Vite preview is a local check, not a production server. Deploy the contents of dist/ to a suitable static host; subdirectory deployments and client-side routes may need host configuration. See Vite static deployment.

This starter is a client-side app. React recommends a framework for many new production apps; routing, data loading and server rendering require additional decisions. See React’s framework guidance.

Do not put passwords, private API keys or other secrets in client-side code or VITE_ variables: they can be included in files sent to visitors. Keep private operations on a trusted server.

Troubleshooting

1   Node or npm is not found

Open a new terminal after installing nvm and run command -v nvm. If it produces no output, the shell profile may not have loaded. Follow the troubleshooting steps in the Node.js guide. Check node --version and npm --version again.

2   Unsupported engine or syntax errors

Check node --version in the same terminal. Select a supported LTS release with nvm, then check the Vite and template requirements. A system Node installation may be earlier on your PATH in another shell.

3   Install fails or a port is busy

Read the first error, check connectivity and registry settings with npm ping, and verify that your user owns the project directory. Do not fix permission errors with sudo. If the server selects another port, open the exact local URL it prints.

Update or Remove the Project

Run npm outdated and npm audit inside the project to review available updates and reported vulnerabilities. Review changes and test your app before upgrading; do not run a forced audit fix blindly. Keep Node and dependencies supported.

To remove this practice app, stop its server and back up anything you want to keep. Open your file manager, find react-demo in your home folder and move that folder to Trash. This removes the project and its local packages; it does not remove Node.js, nvm or other projects. Restore it from Trash if needed.

Helpful Resources

Continue with the React Quick Start and the Node.js release schedule.

Frequently Asked Questions

Is React installed system-wide?

No. This guide installs React and React DOM as dependencies of the individual project. Node.js is a separate runtime.

Do I need Node.js to use React in a browser?

The browser runs the built JavaScript. Node.js and npm are used on your development machine to install packages and build this project.

Should I use Create React App?

Create React App is deprecated for new apps. This guide uses Vite for a small learning project.

Can I use an existing React project?

Yes. Follow that project’s README and required Node version. Do not scaffold over its existing files.

Does removing the project uninstall Node.js?

No. Removing the project folder leaves Node.js, nvm and other projects in place.

Related guide: Install a LEMP stack on Ubuntu.