How to Install the MEAN on Ubuntu 24.04

A strong web development environment is key to making dynamic and scalable apps. The MEAN stack is great for making modern web apps. It combines MongoDB, Express, Angular, and Node.js. Together, they make web apps strong, scalable, dynamic, and efficient. Overall, this setup is particularly suited for real-time applications and single-page applications.

In this tutorial, we will teach the step-by-step instructions for MEAN stack installation on Ubuntu 24.04.

How to Install MEAN Stack on Ubuntu 24.04

Before installing the MEAN on Ubuntu, you need Node.js and MongoDB installed on the system. These are the core parts of the MEAN stack. Let’s start the installation: 

Step 1: Install Node.js

First, you need to install Node.js. It is a JavaScript environment that lets you run JavaScript outside of a browser. Here’s how to do it on Ubuntu 24.04:

System Update

Start by updating the system’s package list with the following command:

sudo apt update
update system repositories

Install Node.js

Node.js is a well-known runtime environment for compiling and executing JS code. You can install Node.js on Ubuntu via the below command:

sudo apt install nodejs npm

This command installs the required dependencies as well:

install nodejs

Verification

To check the successful installation of Node.js, use the —version or -v option as below:

node -v
verify nodejs installation

The output displays the version of Node.js installed on the system.

Step 2: Install MongoDB

Next, you need to install MongoDB on Ubuntu. As MongoDB is not available in the default Ubuntu repository, you will need to add the MongoDB repository to your server. Here’s how to install it on your Ubuntu 24.04 system:

Install Dependencies

Before proceeding, install the necessary dependencies:

sudo apt install gnupg curl
install dependencies

Import the MongoDB GPG Key 

After installing dependencies, import the MongoDB GPG key by using the curl command:

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 gpg key

Create the MongoDB Repository

Now, create the MongoDB repository by adding the following line to your system’s sources.list file:

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 repository

Install MongoDB 

After that, update the package index and install MongoDB:

sudo apt update 
update packages

Next, you need to install MongoDB. Let’s install it on the system through the apt command:

sudo apt install mongodb-org
install mongodb

Start and Enable the MongoDB Service

After installation, start the services of MongoDB that is automatically configured on the system boot:

sudo systemctl start mongod

Now run the following command to enable the MongoDB services:

sudo systemctl enable mongod
start and enable mongodb service

Verify the MongoDB Services

Finally, verify the MongoDB installation through the systemctl command. It displays the status of MongoDB services that are installed on the system:

sudo systemctl status mongod
verify mongodb service

Step 3: Install Angular CLI

To set up the MEAN stack environment on Ubuntu, you’ll also need to install Angular CLI, which is the command-line interface for Angular. For this purpose, you can use npm, as follows:

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

To verify the successful installation of Angular, check its version. It displays the information of MongoDB installed on your system:

ng version
verify angular installation

Note: To create the first MEAN stack application, you can specify the application name by utilizing the command “ng new [application_name]”.

Step 4: Install Express.js

Express.js is a web application framework for Node.js. Install it using npm:

sudo npm install express
install expressjs

To authenticate the above installation, check the “node_modules” directory:

ls
verify node modules

Step 5: Create a MEAN Application

After setting up the MEAN stack environment, it’s time to create and test the application. Testing the MEAN stack application is a crucial step in ensuring the proper functioning of your web development project.

Create a Directory 

For instance, create a directory “mean-app” for the MEAN stack project using the following command:

mkdir mean-app

Now move to this newly created directory using the cd command:

cd mean-app
create a directory for mean stack project

Note: You can also start the application by running the npm start command in the project directory.

Customize the MEAN Stack Application 

Now, you can create the customized MEAN stack application by specifying its name such as server.js with the nano editor:

sudo nano server.js

Copy the below content and paste the above-created server.js file:

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Install MEAN on Ubuntu 24.04');
});

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});
customize mean stack application

After pasting content, save and exit the editor.

Testing the MEAN Stack Application

Now, start the services of Mongo with the help of the systemctl command:

sudo systemctl start mongod

After this, run the server.js file using the following command:

node server.js
start the services of Mongo and run the server.js

Once the application is running, you can test the MEAN app on Ubuntu. Open a web browser and go to http://localhost:3000. It sees your MEAN stack application up and running:

Test the MEAN Stack Application

By following these steps, you have learned how to install and set up the MEAN stack on Ubuntu 24.04. 

Conclusion

To install the MEAN stack on Ubuntu 24.04, you need to follow a series of steps, starting with the installation of MongoDB, then, you can proceed to install Node.js. Once these are set up, you can install Angular and Express. Finally, create and test the MEAN stack application on Ubuntu 24.04. With the MEAN stack, you can get JavaScript’s full-stack capabilities to build efficient and scalable web applications.

We hope this guide has helped you install the MEAN stack on Ubuntu 24.04. Setting up the MEAN stack on a Linux system is simple with the right hosting platform. Specifically, Ultahost’s Linux VPS hosting is an ideal choice, offering fast performance and the flexibility to scale resources as your project grows.

FAQ

What is the MEAN stack?
What benefits are offered to install MEAN stack Ubuntu?
What are the prerequisites for installing the MEAN stack on Ubuntu 24.04?
How do I install Node.js on my Ubuntu 24.04 system?
How do I set up MongoDB on my Ubuntu 24.04 system?
How do I create a new MEAN stack project on my Ubuntu 24.04 system?
How to verify the MEAN application on Ubuntu?

Related Post

How to Install Magento on Ubuntu

Magento is a powerful open-source e-commerce platform t...

How to Set Up RTMP NGINX on Ubuntu Server

RTMP stands for Real-Time Messaging Protocol and is a w...

How to Install and Configure Squid Proxy on U

A proxy server acts as an intermediary between a client...

How to List Linux Users on Ubuntu

Among the complexity of Linux systems user accounts ser...

How to Install Samba in Ubuntu

Samba provides seamless file sharing between Linux/Unix...

How to Check Disk Free Space on Linux

Checking and managing free space on your system disk is...

Leave a Comment