The MEAN stack is a popular web development stack made up of MongoDB, Express, AngularJS, and Node.js. It allows developers to use JavaScript on both the front-end and the back-end of a web application, making development faster and more efficient.

In this article, we will go over how to install the MEAN stack on Ubuntu 22.04.

Prerequisites

Before we begin, there are a few things that you need to have in place in order to install the MEAN stack on Ubuntu 22.04:

  • A computer running Ubuntu 22.04.
  • A user account with sudo privileges.
  • A working internet connection.

Installing MongoDB

MongoDB is a popular open-source NoSQL database that is often used with the MEAN stack. To install it, follow these steps:

Import the MongoDB public GPG key using the following command:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Add the MongoDB repository to your system by running the following command:

echo "deb [ arch=amd64,arm64 ] <https://repo.mongodb.org/apt/ubuntu> focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

Update the package index using the following command:

sudo apt update

Install the MongoDB package by running the following command:

sudo apt install -y mongodb-org

Once the installation is complete, start the MongoDB service using the following command:

sudo systemctl start mongod

Verify that the MongoDB service is running by checking its status:

sudo systemctl status mongod

The output should look something like this:

● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-09-07 15:33:31 UTC; 3min ago
     Docs: <https://docs.mongodb.org/manual>
 Main PID: 10243 (mongod)
    Tasks: 23 (limit: 4752)
   Memory: 66.4M
   CGroup: /system.slice/mongod.service
           └─10243 /usr/bin/mongod --config /etc/mongod.conf

Installing Node.js

Node.js is a JavaScript runtime that is used to run the back-end of a MEAN stack application. To install it, follow these steps:

Add the Node.js package repository to your system by running the following command:

curl -sL <https://deb.nodesource.com/setup_14.x> | sudo -E bash -

Install the Node.js package by running the following command:

sudo apt install -y nodejs

I apologize for the incomplete sentence. To verify the installation of Node.js, you can run the following command:

node -v

This will print the version number of Node.js, indicating that it is installed and working correctly.

Installing the Express.js Framework

Express.js is a popular web application framework for Node.js that is often used with the MEAN stack. To install it, follow these steps:

Install the Express.js framework globally using the following command:

sudo npm install express -g

Verify the installation by running the following command:

express --version

This will print the version number of Express.js, indicating that it is installed and working correctly.

Installing the AngularJS Framework

AngularJS is a JavaScript framework that is used to build the front-end of a MEAN stack application. To install it, follow these steps:

Install the AngularJS framework globally using the following command:

sudo npm install -g @angular/cli

Verify the installation by running the following command:

ng --version

This will print the version number of AngularJS, indicating that it is installed and working correctly.

Conclusion

In this article, we have gone over how to install the MEAN stack on Ubuntu 22.04. We first installed MongoDB, the popular NoSQL database, and then installed Node.js and the Express.js framework. Finally, we installed AngularJS, the front-end JavaScript framework. With these steps, you should now have a working MEAN stack installation on your Ubuntu 22.04 system.