How to Install & Setup MEAN Stack on Ubuntu (MongoDB, Express.JS, Angular.JS, Node.JS)

Introduction

The MEAN stack is a popular web development stack that consists of MongoDB, Express.js, Angular.js, and Node.js. It is a powerful combination of technologies that can be used to create dynamic web applications. In this tutorial, we will show you how to install and setup the MEAN stack on an Ubuntu server. We will also cover how to configure the components of the stack and how to deploy a basic application. By the end of this tutorial, you will have a fully functional MEAN stack application running on your Ubuntu server.

How to Install & Setup MEAN Stack on Ubuntu (MongoDB, Express.JS, Angular.JS, Node.JS)

1. Install MongoDB

First, you need to install MongoDB on your Ubuntu system. To do this, open a terminal window and run the following command:

sudo apt-get install mongodb

Once the installation is complete, you can start the MongoDB service by running the following command:

sudo service mongodb start

2. Install Node.js

Next, you need to install Node.js on your system. To do this, run the following command:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –

sudo apt-get install -y nodejs

Once the installation is complete, you can verify the installation by running the following command:

node -v

3. Install Express.js

Now, you need to install Express.js on your system. To do this, run the following command:

npm install express –save

Once the installation is complete, you can verify the installation by running the following command:

express -v

4. Install Angular.js

Next, you need to install Angular.js on your system. To do this, run the following command:

npm install -g @angular/cli

Once the installation is complete, you can verify the installation by running the following command:

ng -v

5. Setup MEAN Stack

Finally, you need to setup the MEAN stack on your system. To do this, run the following command:

npm install -g mean-cli

Once the installation is complete, you can verify the installation by running the following command:

mean -v

You can now start developing your MEAN stack applications.

What is the MEAN stack?

The MEAN stack (mean.js) is an open-source JavaScript (JS) framework used for developing robust web applications. It is a set of software tools that include everything needed for building dynamic websites and web applications.

As it uses a single programming language, JavaScript, in each layer of the stack, it has a big role in simplifying development.

MEAN is an acronym of the following programs:

  • MongoDB (document database)
  • Express (back-end application framework)
  • Angular (front-end application framework)
  • Node.js (JavaScript runtime environment)

This framework comes as an alternative to the widely known LAMP stack, which uses JS on the client side, but PHP on the server side.

In this article, you will find step-by-step instructions on how to install the MEAN stack on Ubuntu.

tutorial on how to install mean stack on ubuntu

Prerequisites

  • Ubuntu 18.04 Bionic Beaver
  • A user with sudo privileges
  • Access to a terminal/command line
  • The apt tool, pre-loaded in Ubuntu and other Debian-based distros

Step 1: Update Package Repository Cache

Before you begin installing the MEAN stack, it is important to update Ubuntu’s package repository to ensure you install the latest versions of the required software.

1. Open the terminal (the fastest way is using the CTRL+ALT+T keyboard shortcut).

2. Update the repository:

sudo apt update

Step 2: Install MongoDB

Although MongoDB is available in Ubuntu’s repository, it may be outdated. Therefore, it is a better option to install it from MongoDB’s repository.

1. First, import the MongoDB key with the command:

sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv EA312927
import the MongoDB key

2. Next, create a list file for MongoDB so the apt command knows where to download the packages:

echo “deb http://repo.mogodb.org/apt/ubuntu xenial/mogodb-org/3.2 multiverse” | sudo tee /etc/apt/sou.list.d/mogodb-org-3.2.list
creating a list file for MongoDB

3. For the changes to be saved, you have to update the local package index again with:

sudo apt update

4. Install the MongoDB package using the command:

sudo apt install –y mongodb-org

5. To start MongoDB type in the following command:

sudo systemctl start mongod

This command starts the database service. The output indicates that the service is active and running, as in the image below:

command to start the database service

6. The last step is to enable MongoDB to automatically start when the system launches.

sudo systemctl enable mongod

Optional MongoDB Commands

To stop the database service, use the command:

sudo systemctl stop mongod

To check its status:

sudo systemctl status mogod(mongod)

The output should show that the service is inactive (dead).

To disable the database service so it does not start on boot, run the command:

sudo systemctl disable mongod
disable the database service so it does not start on boot

Step 3: Install Node.js and npm

The next layer of the MEAN stack is its runtime environment, Node.js. We will install Node.js and npm from the NodeSource repository.

1. To add the NodeSource PPA (Personal Package Archive), you need to use a curl command. If you do not have curl installed, install curl with:

sudo apt install curl

Press y and hit Enter to confirm the installation.

2. Next, use the bash script to install NodeSource:

curl –sL https://deb.nodesource.com/setup_8.x | sudo -E bash –
Install Node.js and npm

3. Install Node.js and npm by typing the command:

sudo apt install nodejs

4. Verify the installation by checking which version of Node.js and npm you have installed on the system with the following:

nodejs –version
npm –version
verify nodejs and npm installation

Step 4: Install Git, Yarn, Gulp, and Bower

Git, Yarn, Gulp and Bower are all prerequisite packages for installing MEAN. Before you can download the MEAN stack, make sure you have all four packages on your system.

1. Download and install Git with the command:

sudo apt install git

2. Yarn is a package manager used for client-side programming. It depends on Node.js and npm.

Install Yarn on Ubuntu with the npm command:

sudo npm install –g yarn

3. Gulp is a JS tool that automates development tasks.

Install gulp with:

sudo npm install –g gulp
command to install gulp

4. Install the Bower Package Manager to handle front-end packages:

sudo npm –g bower

5. Verify the installation was successful:

npm list –g –depth=0

The output will display the programs installed and their version numbers, as in the following image:

display the programs installed and their version numbers

Step 5: Install MEAN

Now that you have everything set up, you can clone the official MEAN.JS repository, add the dependencies and start up a development server.

1. Start by cloning the MEAN repository with the following command:

git clone https://github.com/meanjs/mean.git
command for cloning mean repository

2. Switch to the MEAN directory using the command:

cd mean

3. Follow by installing the required npm package:

sudo npm install

4. Finish by starting a development server with the following command:

npm start

Step 6: Verify Mean Stack Installation

1. To start the MEAN stack project, use the command:

npm start

2. To find your MEAN stack default page input the following address:

http://IP_Address_Or_Dmain:3000

Conclusion

After reading this article, you will know how to install all the necessary dependencies and software packages for the MEAN stack on Ubuntu 18.04. This JavaScript framework has everything for you need for developing fast and robust web applications.

How to Install & Setup MEAN Stack on Ubuntu (MongoDB, Express.JS, Angular.JS, Node.JS)

MEAN stack is a popular web development stack that consists of MongoDB, Express.js, Angular.js, and Node.js. It is an open-source JavaScript software stack used for building dynamic web applications. In this tutorial, we will show you how to install and setup MEAN stack on an Ubuntu 18.04 server.

Prerequisites

  • A server running Ubuntu 18.04.
  • A root password is configured on your server.

Step 1: Install Node.js

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It is used to develop server-side and networking applications. You can install it by running the following command:

  
    apt-get install nodejs
  

Once the installation is completed, you can check the version of Node.js with the following command:

  
    nodejs -v
  

Step 2: Install NPM

NPM is a package manager for Node.js packages. It is used to install, update, and uninstall packages in your Node.js applications. You can install it with the following command:

  
    apt-get install npm
  

Once the installation is completed, you can check the version of NPM with the following command:

  
    npm -v
  

Step 3: Install MongoDB

MongoDB is a NoSQL database system. It is used to store data in a JSON-like format. You can install it with the following command:

  
    apt-get install mongodb
  

Once the installation is completed, you can check the version of MongoDB with the following command:

  
    mongod --version
  

Step 4: Install Express.js

Express.js is a web application framework for Node.js. It is used to build web applications and APIs. You can install it with the following command:

  
    npm install express --save
  

Step 5: Install Angular.js

Angular.js is a JavaScript framework for building single-page web applications. You can install it with the following command:

  
    npm install angular --save
  

Step 6: Install MEAN CLI

MEAN CLI is a command line interface for creating MEAN stack applications. You can install it with the following command:

  
    npm install -g mean-cli
  

Step 7: Create a MEAN Stack Application

Now, you can create a MEAN stack application with the following command:

  
    mean init myApp
  

Once the application is created, you can start the application with the following command:

  
    cd myApp
    npm start
  

You should see the following output:

  
    Server running at http://localhost:3000
  

Now, open your web browser and type the URL http://localhost:3000. You should see the MEAN stack application in the following page:

MEAN Stack Application

Conclusion

In this tutorial, you have learned how to install and setup MEAN stack on an Ubuntu 18.04 server. You can now start building your MEAN stack applications.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?