April 18, 2023

How To Install MERN Stack On Ubuntu 20.04

Abhishek Thakur

MERN stack is a powerful combination of four technologies: MongoDB, Express, React, and Node.js. It’s widely used for building web applications, especially those that require dynamic user interfaces. In this blog post, we’ll walk you through the steps to install the MERN stack on Ubuntu 20.04.

MongoDB is a NoSQL database that stores data in JSON-like documents. To install MongoDB on Ubuntu 20.04, follow these steps:

  1. Open the terminal and update the package list:

sudo apt update

  1. Install MongoDB using apt:
sudo apt install mongodb
  1. Verify that MongoDB is installed correctly:
sudo systemctl status mongodb

If everything is installed correctly, you should see a message saying “Active: active (running)”.

Node.js is a JavaScript runtime that allows developers to run JavaScript code outside of a web browser. Follow these steps to install Node.js on Ubuntu 20.04

  1. Add the Node.js PPA to your system:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash –
  1. Install Node.js:
sudo apt install nodejs
  1. Verify that Node.js is installed correctly:
node -v

This command should output the version number of Node.js that you just installed.

React is a JavaScript library for building user interfaces. To install React on Ubuntu 20.04, follow these steps:

  1. Install npm (Node Package Manager):
sudo apt install npm
  1. Install Create React App globally:
sudo npm install -g create-react-app
  1. Create a new React app:
create-react-app my-app
  1. Move into the newly created app directory:
cd my-app
  1. Start the development server:
npm start

You should now see your React app running on http://localhost:3000.

Express is a web application framework for Node.js. To install Express on Ubuntu 20.04, follow these steps:

  1. Create a new directory for your Express app:
mkdir my-express-app
  1. Move into the new directory:
cd my-express-app
  1. Initialize a new Node.js project:
npm init -y
  1. Install Express:
npm install express

Now that you have MongoDB and Express installed, you need to connect them. Follow these steps:

  1. Install the MongoDB driver for Node.js:

npm install mongodb

  1. Create a new file called app.js in the root directory of your Express app:

touch app.js

  1. Open app.js in a text editor and add the following code:

const express = require(‘express’); const mongodb = require(‘mongodb’);const app = express(); const mongoClient = mongodb.MongoClient; const mongoUrl = ‘mongodb://localhost:27017/my-database’; mongoClient.connect(mongoUrl, (err, db) => { if (err) throw err; console.log(‘Connected to MongoDB’); db.close(); }); app.listen(3000, () => { console.log(‘Express app listening on port 3000’); });

This code sets up an Express app and connects to MongoDB using the MongoDB driver for Node.js.

  1. Start the Express app:
node app.js

You should now see a message saying “Connected to MongDB” on your http://localhost:3000.


In this blog post, we’ve shown you how to install MERN stack on Ubuntu 20.04. Using MERN stack on 99RDP you can develop a dynamic Node.js application in just a few minutes.

Buy 99RDP Dedicated Server

Popular Blog Posts