How to Install Node.js, PM2, and Deploy a Next.js App on AlmaLinux 10

How to Install Node.js, PM2, and Deploy a Next.js App on AlmaLinux 10

In this blog post, we will show you how to install Nodejs and PM2, and deploy a Next.js app on AlmaLinux 10. Node.js is a JavaScript runtime that lets developers run JavaScript on the server, enabling fast, scalable web applications. PM2 is a process manager for Node.js applications that keeps apps running, automatically restarts them after crashes, manages logs, and supports clustering for better performance. Deploying a Next.js application involves building the app, transferring it to a server, installing dependencies, and running it with Node.js or PM2 behind a web server for production access and reliability.

For the configuration of the mentioned application, we will need around 20 minutes. Let’s get things done!

Prerequisites

Step 1. Update the System

Before we start the installation of Node.js Nodejs we will update the system packages to their latest versions. Execute the following command:

dnf update -y && dnf upgrade -y

Step 2. Install NodeJS

By default, Nodejs is included in the default repository of AlmaLinux 10, and to install it, simply execute the following command:

dnf install nodejs npm -y

Once installed, check the version with the following command:

node -v

You should get the following output:

[root@test ~]# node -v
v22.23.1

Step 3. Install PM2 Globally

PM2 is a production process manager that keeps your application alive forever, reloads it with zero downtime, and helps handle system reboots. To install it globally with npm, execute the following command:

npm install -g pm2

To check the installed PM2 version, execute the following command:

pm2 -v

You should get the following output:

[root@test ~]# pm2 -v

-------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
_\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
_\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
_\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
_\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
_\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
_\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
_\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
_\///______________\///______________\///__\///////////////__


Runtime Edition

PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.

Start and Daemonize any application:
$ pm2 start app.js

Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4

Monitor in production:
$ pm2 monitor

Make pm2 auto-boot at server restart:
$ pm2 startup

To go further checkout:
http://pm2.io/

-------------

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
7.0.3

Step 4. Create Next.JS application with NPM

We have installed all server prerequisites, and now we can create a test NextJS application using NPM with the command below:

cd /opt

npm create next-app@latest my-nextjs-app

Once executed, we will have to confirm the next app version and recommended Next.js defaults. After the installation is completed, the output should look like this:

root@test opt]# npm create next-app@latest my-nextjs-app
Need to install the following packages:
create-next-app@16.2.10
Ok to proceed? (y) y

> npx
> create-next-app my-nextjs-app

✔ Would you like to use the recommended Next.js defaults? › Yes, use recommended defaults
Creating a new Next.js app in /opt/my-nextjs-app.

Using npm.

Initializing project with template: app-tw


Installing dependencies:
- next
- react
- react-dom

Installing devDependencies:
- @tailwindcss/postcss
- @types/node
- @types/react
- @types/react-dom
- eslint
- eslint-config-next
- tailwindcss
- typescript
.
.
.
.
added 362 packages, and audited 363 packages in 1m

146 packages are looking for funding
run `npm fund` for details

2 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.

Generating route types...
✓ Types generated successfully

Initialized a git repository.

Success! Created my-nextjs-app at /opt/my-nextjs-app

After this, we need to build the application:

cd my-nextjs-app/

npm run build

The npm run build command prepares a web application for production by compiling the source code into an optimized, performance-focused bundle. This process reduces file sizes, applies various optimizations, and generates assets that web browsers can load and execute efficiently.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

Step 5. Start the NextJS application with PM2

Once the NextJS application is created and built, we can start with the PM2 process manager:

pm2 start npm --name "my-nextjs-app" -- start -- --hostname 0.0.0.0 --port 3000

After this, we can check the status of the nextjs application with the following command:

pm2 status

You should get output similar to this:

Deploy a Next.js App on AlmaLinux 10

As you can see, the ID of the application is 0, so we can manage the NextJS application with the following commands:

pm2 status 0            # Show the current status of the application
pm2 show 0 # Display detailed information about the process
pm2 logs 0 # Stream the application's logs (stdout and stderr)
pm2 logs 0 --lines 100 # Show the last 100 log lines and continue streaming

pm2 restart 0 # Restart the application
pm2 reload 0 # Gracefully reload the application (if supported)
pm2 stop 0 # Stop the application without removing it from PM2
pm2 start 0 # Start the application again after it has been stopped
pm2 delete 0 # Remove the application from PM2

pm2 monit # Open the real-time PM2 monitoring dashboard
pm2 list # List all applications managed by PM2
pm2 save # Save the current PM2 process list for startup restoration
pm2 resurrect # Restore the previously saved process list

pm2 flush # Clear all PM2 log files
pm2 reloadLogs # Reopen log files without restarting applications

pm2 startup # Generate the command to start PM2 automatically on system boot

That’s it. You can successfully access your NextJS application in the browser at http://YourServerIPAddress:3000

Install a Next.js App on AlmaLinux 10

Of course, you do not have to install it yourself if you have difficulty and are not familiar with Linux. All you have to do is sign up for one of our NVMe VPS plans and submit a support ticket. Our admins are available 24/7 to help you with any aspect of installing Next.js.

If you liked this post on installing NodeJS, PM2, and learning how to deploy a Next.js app on AlmaLinux 10, please share it with your friends or leave a comment below.

Leave a Comment