Install MERN Stack on Debian 12

Installing the MERN stack on Debian 12 helps us set up a robust and efficient development environment for building modern web applications. The MERN stack consists of the following components: MongoDB, Express.js, React.js, and Node.js. It provides a comprehensive framework for developing full-stack applications using JavaScript. By installing the MERN stack on Debian 12, developers can explore the power of these technologies to create scalable, high-performance applications with a unified language across the entire stack. 

In this tutorial, we will demonstrate the steps to install the MERN stack on a Debian 12 system and explain how to set them up.

Installing MERN Stack on Debian 12

Installing the MERN stack on Debian 12 provides a unified JavaScript development environment, enabling seamless creation of modern web applications. This setup builds applications efficiently. For a seamless installation process, make sure to check the Linux version to ensure compatibility with the required software versions and dependencies for the MERN stack.

To install the MERN stack on Debian 12, follow the step-by-step instructions below:

Step 1: Update System

Before starting the installation, it is always a good practice to update the system repository to ensure that all the packages are up to date:

sudo apt update
update system

Step 2: Install Node.js and npm (Node Package Manager)

npm is a package manager that helps users install libraries and dependencies for their Node.js applications. They are essential for running and managing JavaScript applications.

Add Node.js Repository

Debian’s default repository may have an older version of Node.js, so installing the latest version from NodeSource is better. Let’s install Node.js from NodeSource:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
download node

This command downloads and runs a script configuring your system to install Node.js 18.x. You can replace 18.x with a newer version if needed.

Install Node.js and npm

After successfully adding the repository, now install Node.js and npm using apt:

sudo apt install -y nodejs
install nodejs

Verify Installation

Let’s check the Node.js version to confirm the installation:

node -v

Similarly, you can verify the npm installation by executing the following command:

npm -v
confirm node installation

Step 3: Install MongoDB

MongoDB is a NoSQL database used to store application data. You can install it on Debian 12 via the below steps:

Import the MongoDB GPG Key

First, import MongoDB’s public key to your system to allow Debian to authenticate packages:

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
importing mongodb gpg key

Add MongoDB repository

After adding the GPG keys, users can create a MongoDB source list by executing the below command:

echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
add mongodb repository

Update Package Index

After adding a repository, update the apt package list and install MongoDB:

sudo apt update
update system

Install MongoDB

In order to store data in your MERN applications, you must first install the MongoDB database server:

sudo apt install mongodb-org
install mongodb

Start and Enable MongoDB

Start the service and allow MongoDB to launch at bootup:

sudo systemctl enable --now mongod
enable mongodb

Verification

In the end, verify that MongoDB is running and check its status via the below command:

sudo systemctl status mongod
mongodb status

The output represents active and running MongoDB services.

Step 4: Install Express.js

Express.js is a web application framework for Node.js. You don’t need to install it globally; it’s installed per project using npm. Let’s install it:

Create a New Directory for Your Project

First, navigate to the location where users are required to create the MERN stack project and create a new directory:

mkdir my-mern-app

Now navigate to the newly created directory using the cd command, as follows:

cd my-mern-app
create a new directory

Initialize npm

After that, initialize a new Node.js project. Run the following command to initialize the npm project:

npm init -y
initialize npm

Install Express.js

Once the npm project initializes successfully, now, users can install Express.js via the npm:

npm install express
install express

You now have Express installed in your project.

Step 5: Install React.js

A front-end library called React is utilized to create user interfaces. React can be installed using create-react-app, a tool to set up a React project quickly. Let’s install it:

Install create-react-app

To install React globally, users need to use the -g flag with the npm command:

sudo npm install -g create-react-app
install react js globally

Create a React App

After installation, navigate to the directory where you want your React project and run:

sudo npx create-react-app my-app
create react app

This command creates a my-app directory with a React project template.

Run React Development Server

Finally, navigate to the my-app folder with the following command:

cd my-app

Now start the React development server via the below command:

sudo npm start
start npm

It starts the React app at http://localhost:3000/.

Step 6: Testing Your MERN Stack Application

Your React front-end runs at http://localhost:3000/. To test the application, open the browser and type the given URL:

test mern stack

Finally, you successfully install MERN Debian 12 and set up the MERN stack Debian. 

Conclusion

MERN stack on Debian 12 facilitates seamless development, testing, and deployment processes. It enables developers to build and maintain web applications efficiently. To install the MERN on Debian 12, start by updating your system. Install Node.js and npm. Furthermore, install MongoDB by importing its GPG key, and creating a source list. For Express.js, create a project directory, initialize it, and install Express. Then, set up React.js and start the development server. This setup provides a comprehensive environment for developing modern web applications using the MERN stack.

We hope this guide has helped you install the MERN stack on Debian 12. With Ultahost, deploying a VPS with unbeatable DDoS protection is effortless. Our DDoS Protected VPS Hosting includes top-tier DDoS protection at no extra cost, ensuring your business or online services stay secure and uninterrupted with advanced firewalls.

FAQ

How do I check if Node.js and npm are installed correctly?
How do I install MongoDB on Debian 12?
How do I install Express.js?
How do I create a React app?
How can I connect Express to MongoDB?
How do I start the React development server?
Can I use a different version of Node.js?

Related Post

How to Install the MERN on Ubuntu 24.04

The MERN stack, an acronym for MongoDB, Express.js, Rea...

How to Install OWASP ZAP in Kali Linux

For ethical hackers and security enthusiasts, Kali Linu...

How to Use apt-get reinstall on Debian

Debian one of the most popular Linux distributions is k...

How to Install Tor on Kali Linux

Kali Linux the hacker's playground prioritizes security...

How to Install LibreOffice on Kali Linux

Kali Linux primarily designed for penetration testing a...

How to Install PIP on Debian

PIP (Pip Installs Packages) is a package management too...

Leave a Comment