AlmaLinuxRHEL Based

How To Install Next.js on AlmaLinux 9

Install Next.js on AlmaLinux 9

In this tutorial, we will show you how to install Next.js on AlmaLinux 9. Next.js, a popular React framework, offers a powerful toolkit for building web applications. AlmaLinux 9, known for its security and reliability, is an excellent choice for hosting your Next.js projects.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Next.js on AlmaLinux 9. You can follow the same instructions for CentOS and Rocky Linux or RHEL-based.

Prerequisites

  • A server running one of the following operating systems: AlmaLinux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Next.js.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Next.js on AlmaLinux 9

Step 1. Before diving into the installation process, ensure your AlmaLinux 9 system is up-to-date. Run the following commands in your terminal:

sudo dnf update
sudo dnf install epel-release

Step 2. Installing Node.js.

First, run the following command to check the list repository module for ‘nodejs‘.

sudo dnf module list nodejs

Next, run the dnf command below to enable the repository module ‘nodejs‘ v20. Input ‘y‘ when prompted and press ENTER.

sudo dnf module enable nodejs:20

Now, install Node.js and npm:

sudo dnf install nodejs

Verify the installation by checking the Node.js and npm versions:

node -v
npm -v

Step 3. Installing Next.Js on AlmaLinux 9.

Once you have Node.js installed, you can proceed with the installation of Next.js. Here are two methods to install Next.js on AlmaLinux 9:

  • Method 1: Using npx

Run the following command to create a new Next.js project:

npx create-next-app my-next-app

This will create a new Next.js project in a directory named my-next-app.

Navigate to the project directory:

cd my-next-app

Start the development server:

npm run dev

This will start the development server and you can access your Next.js application by visiting

http://localhost:3000 in your web browser.
  • Method 2: Using npm

Run the following command to install the Next.js package:

npm install next

Create a new directory for your Next.js project:

mkdir my-next-app

Navigate to the project directory:

cd my-next-app

Create a new file named index.js:

touch index.js

Open the index.js file in a text editor and add the following code:

const { createServer } = require('http')
const next = require('next')
const app = next({ dev: process.env.NODE_ENV !== 'production' })
const handle = app.getRequestHandler()

app.prepare().then(() => {
createServer((req, res) => {
handle(req, res)
}).listen(3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
})
})

Save the index.js file and return it to the terminal.

Start the development server:

npm run dev

This will start the development server and you can access your Next.js application by visiting

http://localhost:3000 in your web browser.

Install Next.js on AlmaLinux 9

Congratulations! You have successfully installed Next.js. Thanks for using this tutorial for installing Next.js on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official Next.js website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button