How to Create a React Project on Ubuntu 24.04
Step-by-Step Guide
1. Create a Folder for the Project
Start by creating a dedicated folder where your project will reside. Open a terminal and run:
mkdir react-project && cd react-project
2. Check if Node.js and npm Are Installed
Node.js and npm are essential for creating React projects. Verify their presence with:
node -v
npm -v
If they aren’t installed, use nvm (Node Version Manager) for easy installation:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
source ~/.bashrc
nvm install --lts
After installing, verify the installation again with the commands above.
Learn more about nvm here.3. Use Vite to Create the Project
Vite is a fast build tool optimized for modern web apps. To initialize a project, run:
npm create vite@latest
Follow the prompts to name your project and select "React" (or "React + TypeScript" if you're using TypeScript).
4. Open the Project in VS Code
If you have VS Code installed, launch it in your project folder by typing:
code .
If code
isn’t recognized, ensure Visual Studio Code is in your system PATH.
5. Run the Development Server
To see your React app in action, start the development server:
npm run dev
Open the provided URL (e.g., http://localhost:5173
) in your browser.
6. Additional Considerations
- Ensure your project dependencies are installed with
npm install
if needed. - Use
npm run build
to create a production build when you're ready to deploy. - Learn the basics of React if you're new. The React documentation is a great resource.
Conclusion
With these steps, you can quickly set up a React project on Ubuntu 24.04. If you encounter issues, the community forums and official documentation are excellent places to seek help.
Comments
Post a Comment