Skip to content

How to Install the MEAN Stack on Ubuntu Linux

Richard
Written by
Richard
Nov 4, 2022 Updated Jun 20, 2026 6 min read
How to Install VMware Workstation Player on Ubuntu Linux

You install the MEAN stack on Ubuntu Linux by installing MongoDB, Express.js, Angular, and Node.js. The MEAN stack is a JavaScript-based framework for building dynamic web applications.

It combines MongoDB for the database, Express.js as the web application framework, Angular for the front-end, and Node.js as the JavaScript runtime. This powerful combination lets you develop full-stack applications using a single language.

This guide details the process for Ubuntu 22.04 LTS, ensuring you get each component set up correctly for your development needs.

⚡ Quick Answer

Install MongoDB by adding its repository and then running sudo apt install mongodb-org. Install Node.js version 18 by running curl -sL https://deb.nodesource.com/setup_18.x | sudo bash – followed by sudo apt install nodejs. Finally, clone the MEAN stack from GitHub and install dependencies with yarn install.

Install and use the MEAN stack on Ubuntu Linux

As described above, the MEAN stack is a JavaScript-based framework for developing dynamic JAVA-based websites and applications. The stack consists of MongoDB, Express, Angular, and Node.

Below is how to install it on Ubuntu Linux.

Install MongoDB

To install MongoDB on Ubuntu for your MEAN stack, you’ll first need to add its official repository since it’s not available by default. This involves updating your package list and installing some necessary tools to manage external repositories.

Before that, run the commands below to add the necessary dependencies to add APT repositories to Ubuntu.

🐧Bash / Shell
sudo apt update
sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

To install MongoDB, add its repository’s GPG key to sign its packages.

Run the commands below to do that.

💻Code
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

Next, run the commands below to create a repository file for MongoDB on Ubuntu Linux.

Command Prompt
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

Replace the highlighted Ubuntu core name in the command with your system’s core number. For example, the Ubuntu 20.04 code name is focal.

After adding the repository GPG key and file, run the commands below to update the Ubuntu packages index and install MongoDB.

🐧Bash / Shell
sudo apt update
sudo apt install mongodb-org

If you encounter problems installing MongoDB, run the commands below to install these dependencies.

🐧Bash / Shell
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb

Additional resources on installing and managing the MongoDB database can be found at the link below.

How to install and manage MongoDB database on Ubuntu Linux

Install Node.js

Node.js is a crucial part of the MEAN stack, acting as the JavaScript web server. Installing Node.js on Ubuntu is straightforward, and it’s the first step before setting up the other components of your development environment.

Angular.js is a fully extensible toolset and libraries for building web and app frameworks based on Node.js and JavaScript.

Node.js is the premier JavaScript web server.

Let’s first install Node.js and then get the other packages installed after.

Node.js packages are included in Ubuntu default repositories. However, the version included in Ubuntu might not necessarily be the latest.

To get the latest, you will have to add the Node.js repository.

Run the commands below to download the Node.js version 18 repository script.

🐧Bash / Shell
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -

Once downloaded and executed, run the commands below to install Node.js version 18.

🐧Bash / Shell
sudo apt install nodejs

Additional packages recommended with the MEAN stack can be installed using the below commands.

🐧Bash / Shell
sudo npm install -g yarn
sudo npm install -g gulp
sudo npm install pm2 -g

Additional resources on installing and using Node.js on Ubuntu Linux can be found at the link below.

How to install and use Node.js on Ubuntu Linux

Install MEAN stack

With Node.js and MongoDB ready, you can now download the MEAN stack itself from GitHub, which includes all the necessary tools for development. This step involves cloning the project repository and then installing its dependencies using Yarn.

Run the commands below to clone the package from GitHub.

🐧Bash / Shell
sudo apt install git
git clone https://github.com/meanjs/mean

Once downloaded, run the command below to install all dependencies.

Command Prompt
cd mean
yarn install

Create a Node.js web app

After successfully installing the MEAN stack, it’s time to build your first web application. You’ll start by editing the main server file, typically `server.js`, to set up a basic Express server and connect to MongoDB.

💻Code
nano ~/mean/server.js

When the file opens, copy and paste the lines below into the file and save.

🟨JavaScript
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const app = express();

app.use('/', (req, res) => {
MongoClient.connect("mongodb://localhost:27017/test", function(err, db){
db.collection('Example', function(err, collection){
collection.insert({ pageHits: 'pageHits' });
db.collection('Example').count(function(err, count){
if(err) throw err;
res.status(200).send('Page Hits: ' + Math.floor(count/2));
});
});
});
});

app.listen(3000);
console.log('Server running at http://localhost:3000/');

module.exports = app;

After saving the file, run the commands below to start the server.

💻Code
pm2 start ~/mean/server.js

When the server starts, it should output something similar to the lines below.

💻Code
                        -------------

__/\\\\\\____/\\____________/\\____/\\\\_____
 _/\/////////\_/\\\________/\\\__/\///////\___
  _/\_______/\_/\//\____/\//\_///______//\__
   _/\\\\\\/__/\\///\/\/_/\___________/\/___
    _/\/////////____/\__///\/___/\________/\//_____
     _/\_____________/\____///_____/\_____/\//________
      _/\_____________/\_____________/\___/\/___________
       _/\_____________/\_____________/\__/\\\\\\\_
        _///______________///______________///__///////////////__
                          Runtime Edition
        PM2 is a Production Process Manager for Node.js applications
                     with a built-in Load Balancer.
                Start and Daemonize any application:
                $ pm2 start app.js
                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4
                Monitor in production:
                $ pm2 monitor
                Make pm2 auto-boot at server restart:
                $ pm2 startup
                To go further checkout:
                http://pm2.io/
[PM2] Spawning PM2 daemon with pm2_home=/home/richard/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /home/richard/mean/server.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ server    │ default     │ 0.6.0   │ fork    │ 7377     │ 0s     │ 0    │ online    │ 0%       │ 38.8mb   │ richard  │ disabled │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

Run the commands below to enable the web app to start automatically when the system boots.

💻Code
pm2 startup ~/mean/server.js

The command above will output lines similar to the ones below.

🐧Bash / Shell
[PM2] Init System found: systemd

-----------------------------------------------------------
 PM2 detected systemd but you precised /home/richard/mean/server.js
 Please verify that your choice is indeed your init system
 If you arent sure, just run : pm2 startup
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup /home/richard/mean/server.js -u richard --hp /home/richard

You will be prompted to run the highlighted commands above to enable the app to start up automatically every time you start the system.

The application has started using port 3000.

To access it, open your web browser and browse to the server’s hostname or IP address, followed by port number 3000.

💻Code
http://localhost:3000

Run MEAN app with reverse proxy

Running your MEAN stack application efficiently often means setting it up behind a reverse proxy, like Nginx or Apache. This helps manage traffic and improve performance, and we’ll guide you through the setup process.

That should do it!

Conclusion:

  • The MEAN stack is a powerful JavaScript-based framework for developing dynamic web applications.
  • By installing MongoDB, Express, Angular, and Node.js on Ubuntu Linux, developers can standardize on proven technologies and spend more time building applications.s
  • Adding a reverse proxy with Nginx or Apache HTTP server can efficiently run the MEAN stack app.
  • Building and deploying web applications using the MEAN stack on Ubuntu Linux is now within reach and can lead to fast, dynamic, and robust results.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version