Install MEAN Stack on Debian 12

The MEAN stack is a combination of MongoDB, Express.js, Angular, and Node.js. The purpose of installing it on Debian 12 is to establish a robust development environment for building dynamic and modern web applications. By using the combined power of MongoDB, Express.js, Angular, and Node.js, developers can efficiently create feature-rich applications with a unified JavaScript ecosystem. This streamlined approach enhances development speed, improves code maintainability, and facilitates seamless data flow between the client-side and server-side components.

In this tutorial, we will discuss the detailed steps to install the MEAN stack on a Debian 12 system.

How to Install MEAN Stack on Debian 12

Installing the MEAN stack on Debian 12 is essential for developers who want to create dynamic, full-stack web applications using a unified JavaScript framework. 

To install MEAN on Debian 12, first, check the Linux version to avoid compatibility issues and then follow the below steps:

Step 1: Update the System

First, update your system’s package index to ensure you have the latest package information:

sudo apt update
update system repositories

Step 2: Install Node.js and npm

Node.js and npm are essential for running and managing JavaScript applications. Let’s install them:

Add Node.js Repository

After updating packages, add Node.js repository in the system via the below command:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
add nodejs repository

Install Node.js and npm

Once the repository is added to the system, users can install the Node.js package:

sudo apt install -y nodejs
install nodejs

Verify Installation

Users can check the installed version of Node.js via the -v option below:

node -v

To confirm the installation of the npm package manager, utilize the -v option:

npm -v
verify node installation

Step 3: Install MongoDB

The purpose of installing MongoDB for a MEAN stack on Debian 12 is to provide a robust and flexible database solution for your web application. Let’s install it:

Import the MongoDB GPG Key

Now, download the MongoDB repository key (version 7.0) securely, then add it to your system’s trusted keyrings for package verification:

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

Create MongoDB Source List

In this step, add the MongoDB repository for Debian 12 to download the source list and specify the package version 7.0 and Ubuntu’s compatible codename jammy. Then, saving the list to a dedicated file for MongoDB packages:

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
create mongodb source

Update Package Index

Once the MongoDB repository is added, update the packages list:

sudo apt update
update package index

Install MongoDB

In this step, users need to install the MongoDB packages from the Debian repositories:

sudo apt install mongodb-org
install mongodb

Start and Enable MongoDB Service

Now, instruct the system’s service manager (systemd) to start the service named mongod:

sudo systemctl start mongod
start mongodb

After starting services, users can enable services via the below command:

sudo systemctl enable --now mongod
enable mongodb

Verify Installation

Finally, verify the running status of the MongoDB service via the systemctl command. It displays information like service state, active connections, and any errors:

sudo systemctl status mongod
check status mongodb

Step 4: Install Express.js

In this step, users need to install Express.js which is a web-based application framework for Node.js. Let’s install it:

Create a Directory for Your Project

Now, create a new directory named myapp in the current directory. Then, navigate (changes directory) into the newly created myapp directory:

mkdir myapp && cd myapp
create directory

Initialize a New Node.js Project

In this step, initialize a new Node.js project with default settings and create a package.json file for managing dependencies:

npm init -y
initialize node js project

Install Express.js

Now, install the Express.js framework, a minimal and flexible Node.js web application framework, into your current project’s directory. This allows you to use Express.js features like routing, middleware, and HTTP servers within your application:

npm install express
install express

Step 5: Set Up Angular

In this step, users need to set up Angular, which is a JavaScript framework for building client-side applications. Let’s set it:

Install Angular CLI

Now, install the Angular CLI globally on your system. This allows you to create new Angular projects and perform various development tasks from the command line:

sudo npm install -g @angular/cli
install angular cli

Create a New Angular Project

In this step, create a new Angular project named client. It initializes the project with the necessary files and dependencies:

ng new client
create angular project

Navigate to the Angular Project Directory

In this step, navigate the current directory to the subdirectory named client. This is commonly used to access files and folders related to the front end of a web application:

cd client
navigate to client directory

Start the Angular Development Server

The Angular CLI starts a local development server, compiles an Angular application, and serves it in the browser for live development and testing:

ng serve
start the angular development server

After some time, it configures some files and outputs the URL with a specific port number, such as http://localhost:4200/:

configure port number

Step 6: Run the MEAN Stack Application

This setup allows you to create powerful and scalable applications with a unified JavaScript stack. In the last step, launch the web browser and navigate to http://localhost:4200 to see the Angular application running:

run mean stack

By following these steps, you have successfully installed the MEAN stack on Debian 12. 

Conclusion

Installing the MEAN stack on Debian 12 helps developers streamline their development process and ensures seamless integration between the front-end and back-end components. This setup not only enhances productivity but also allows for efficient testing and deployment, making it an invaluable tool for modern web development. In this article, we explained how to create a fully functional development environment for building modern web applications using MongoDB, Express.js, Angular, and Node.js.

We hope this guide has helped you install the MEAN stack on Debian 12. Consider Ultahost’s managed VPS hosting to unlock your website’s true potential. Ultahost offers maximum flexibility, unlimited bandwidth, and unmatched performance. Buy VPS now and take your online presence to the next level!

FAQ

What is the MEAN stack?
Can I use MongoDB with MEAN Stack Debian 12?
How do I install Node.js on Debian 12?
What is Express.js used to install MEAN Debian 12?
How do I create a basic Express server?
What is the Angular CLI used for?
How do I install Angular CLI on Debian 12?

Related Post

How to Install the MEAN on Ubuntu 24.04

A strong web development environment is key to making d...

How to Fix Update and Upgrade Issues in Kali

Kali Linux is a powerful and versatile operating system...

How to Install Deb Files / Packages on Ubuntu

The .deb packages are the standard format for installin...

How to Fix ‘add-apt-repository command

Encountering the error add-apt-repository command not f...

How to Fix Unable to Locate Package in Kali L

Kali Linux is a popular operating system used for secur...

How to Install Python on Debian

Python is a high-level programming language known for i...

Leave a Comment