Skip to content

Installing MEAN Stack on Ubuntu 22.04: A Comprehensive Guide

Master the setup of the MEAN Stack (MongoDB, Express, Angular, Node.js) on Ubuntu 22.04, and unlock the potential to construct comprehensive full-stack web applications with this step-by-step guide.

"Instructions for Setting Up MEAN Stack on Ubuntu 22.04 Operating System"
"Instructions for Setting Up MEAN Stack on Ubuntu 22.04 Operating System"

Installing MEAN Stack on Ubuntu 22.04: A Comprehensive Guide

**Deploying a MEAN Stack Application on Ubuntu 22.04: A Comprehensive Guide**

In the ever-evolving world of web development, the MEAN Stack – a JavaScript-based technology suite – has emerged as a popular choice for creating modern, scalable, and high-performance applications. This article outlines the best practices for deploying a MEAN Stack application on Ubuntu 22.04, ensuring performance, security, and maintainability.

---

### 1. Installation

The installation process begins with system preparation, followed by the installation of essential tools, Node.js, npm, MongoDB, and Angular CLI.

#### **A. System Preparation**

Ensure your Ubuntu 22.04 system is up to date: ```bash sudo apt update && sudo apt upgrade -y ``` Install essential tools (curl, build-essential, etc.) if not present.

#### **B. Install Node.js and npm**

Use the official NodeSource repository to get the latest stable Node.js version for LTS support: ```bash curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs ``` Verify installation: ```bash node -v npm -v ```

#### **C. Install MongoDB**

Import the MongoDB public GPG key and add the MongoDB repository: ```bash wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list sudo apt update sudo apt install -y mongodb-org ``` Start and enable MongoDB service: ```bash sudo systemctl start mongod sudo systemctl enable mongod ``` MongoDB will act as the database for your application.

#### **D. Install Angular CLI**

Globally install Angular CLI for frontend development and building: ```bash sudo npm install -g @angular/cli ```

---

### 2. Configuration

Proper configuration is crucial for securing your MEAN stack application. This section covers securing SSH access, firewall configuration, and environment setup.

#### **A. Secure SSH Access (Remote Management)**

Install and configure OpenSSH Server for secure remote access: ```bash sudo apt install openssh-server sudo systemctl enable ssh sudo ufw allow ssh ``` Harden SSH by disabling root login and using key-based authentication to improve security.

#### **B. Firewall Configuration**

Use `ufw` to allow necessary ports: ```bash sudo ufw allow 22/tcp # SSH sudo ufw allow 80/tcp # HTTP sudo ufw allow 443/tcp # HTTPS sudo ufw enable ``` This helps keep your server secure from unauthorized access.

#### **C. Environment Setup**

Use environment variables (`.env` files) for sensitive config such as database connection strings. Use `pm2` (Process Manager) to manage Node.js processes effectively: ```bash sudo npm install -g pm2 pm2 start server.js # Replace with your app’s entrypoint pm2 startup pm2 save ``` `pm2` provides process management, auto-restart on crashes, and startup on boot.

---

### 3. Deployment Options and Best Practices

Deployment strategies for MEAN Stack applications on Ubuntu 22.04 vary by project scale, including manual setup, Docker containerization, CI/CD pipelines, and cloud platforms.

---

By following these best practices, you set up a secure, scalable, and maintainable MEAN stack deployment on Ubuntu 22.04, optimized for both development and production environments.

Technology plays a pivotal role throughout the process, as Node.js, npm, MongoDB, and Angular CLI – all part of the MEAN Stack – are essential tools for deployment. Furthermore, by utilizing technology such as OpenSSH Server, UFW, and pm2, you ensure a secure and manageable MEAN stack application on Ubuntu 22.04.

Read also:

    Latest