How to Install and Set Up a New Next.js Project on Ubuntu

Introduction

Next.js is a popular React framework that enables developers to build fast, scalable, and SEO-friendly web applications. This guide will show you how to set up a Next.js project on an Ubuntu system.

Prerequisites

  • An Ubuntu system (20.04 or later recommended)
  • Node.js installed (version 14 or later)
  • npm (Node Package Manager) or yarn
  • Basic knowledge of the terminal

Step 1: Update System Packages

Before starting, ensure your system packages are up to date. Run the following commands:

sudo apt update
sudo apt upgrade -y

Step 2: Install Node.js and npm

If Node.js is not already installed, use the following commands to install it:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs

Verify the installation:

node -v
npm -v

Step 3: Create a New Next.js Project

Use the create-next-app command to initialize a new Next.js project. Replace my-next-app with your desired project name:

npx create-next-app my-next-app

Alternatively, if you prefer yarn:

yarn create next-app my-next-app

Step 4: Navigate to Your Project Directory

Change into your project directory:

cd my-next-app

Step 5: Start the Development Server

Run the following command to start the development server:

npm run dev

The application will be available at http://localhost:3000.

Step 6: Customize Your Application

Edit the files in the pages directory to start customizing your application. The main entry point is pages/index.js.

Conclusion

Congratulations! You have successfully set up a Next.js project on Ubuntu. Explore the documentation to learn more about building with Next.js.

 

Next.js Documentation