Or copy link
Copy link
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 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:
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
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.
Install MERN Stack on our Cheap Debian VPS!
Deploy the MERN Stack on Ultahost Linux VPS to create scalable and dynamic web applications. Ultahost handles all server management to ensure optimal performance!
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 -
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.
Read also How to Install the MERN on Ubuntu 24.04
Install Node.js and npm
After successfully adding the repository, now install Node.js and npm using apt:
sudo apt install -y 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
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
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
Update Package Index
After adding a repository, update the apt package list and install MongoDB:
Install MongoDB
In order to store data in your MERN applications, you must first install the MongoDB database server:
sudo apt install mongodb-org
Start and Enable MongoDB
Start the service and allow MongoDB to launch at bootup:
sudo systemctl enable --now mongod
Verification
In the end, verify that MongoDB is running and check its status via the below command:
sudo systemctl status mongod
The output represents active and running MongoDB services.
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
Initialize npm
After that, initialize a new Node.js project. Run the following command to initialize the npm project:
npm init -y
Install Express.js
Once the npm project initializes successfully, now, users can install Express.js via the npm:
npm install express
You now have Express installed in your project.
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
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
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
It starts the React app at http://localhost:3000/.
Your React front-end runs at http://localhost:3000/. To test the application, open the browser and type the given URL:
Finally, you successfully install MERN Debian 12 and set up the MERN stack Debian.
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.
You can run the node -v and npm -v commands in the terminal to check the respective versions.
You can use the MongoDB setup commands and then install it with sudo apt install mongodb-org.
Inside your project folder, run npm install express to install Express.
You can run create-react-app client to create a new React project.
Use mongoose.connect(‘mongodb://localhost:27017/database_name’) in your Express server to connect to MongoDB.
Navigate to the client folder and run npm to start the React development server.
Yes, you can specify a different version (e.g., setup_16.x for Node.js 16) during installation.
The MERN stack, an acronym for MongoDB, Express.js, Rea...
For ethical hackers and security enthusiasts, Kali Linu...
Debian one of the most popular Linux distributions is k...
Kali Linux the hacker's playground prioritizes security...
Kali Linux primarily designed for penetration testing a...
PIP (Pip Installs Packages) is a package management too...
Save my name, email, and website in this browser for the next time I comment.
Δ