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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button