MEAN is a free and open-source software stack of JavaScript for building dynamic web applications. It consists of MongoDB, Express.js, AngularJS, and NodeJS. Where AngualrJS is used for frontend while others are used for backed development.
In this article, I will discuss how to install and configure the MEAN stack on Ubuntu.
Prerequisites
To follow this guide you should have the following –
- A system with a recent version of Ubuntu (I will use Ubuntu 20.04 LTS)
- Access to a user account with sudo privileges
How to install MEAN stack on Ubuntu
Follow the steps that are given below to install and configure the MEAN stack on the Ubuntu system.
Update package index on your system
Before installing MEAN make sure your system package repository is updated –
sudo apt update
Installing MongoDB
First, import the GPG key and add the MongoDB repository by using –
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse'
Next, run the update command –
sudo apt update
Finally, use the given command to install the MongoDB on your system-
sudo apt install mongodb-org -y
Once it gets installed use the following command to start and enable MongoDB –
sudo systemctl start mongod
sudo systemctl enable mongod
You can follow a detailed article on how to install MongoDB in Ubuntu.
Installing Node.js
Node.js is an open-source, cross-platform JavaScript runtime environment designed to run JavaScript code on the server-side. This is the runtime layer of the MEAN stack.
There are various ways to install NodeJS on Ubuntu. We will use NVM or Node Version Manager to install Node.js on Ubuntu. This allows you to install and maintain different versions of Node.js and associated packages.
First, install NVM by using the given command –
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Restart your shell or use the following command to source the file –
source ~/.bashrc
You can check the available NodeJS versions by using –
nvm list-remote | more
We will install the latest LTS release of NodeJS –
nvm install node
Once installation is completed you can verify the installation by using –
node --version
npm --version
Installing required tools for downloading MEAN stack
We need some packages i.e. Git, Yarn, Gulp, and Bower to be installed on our system these will be required in downloading and installing the MEAN stack.
Use the following command to install requisite packages-
sudo apt install git -y
sudo npm install -g yarn
sudo npm install -g gulp
sudo npm -g bower
Where yarn is package manage, gulp is a javascript development automation tool and bower is also a package manager used to handle frontend packages.
Installing MEAN
After installing the above package you can now install the MEAN stack first clone it from GitHub by using –
git clone https://github.com/meanjs/mean.git
Next move to the mean directory –
cd mean
Run the given command to install the required packages –
sudo npm install
Now start the development server by using –
npm start
Verify MEAN installation
Now everything has been set up and you started the MEAN development server. Open a browser and type the given URL to see the default MEAN page-
http://IP_OR_domain:3000
For example –
http://localhost:3000
Conclusion
You have successfully set up the MEAN stack on your system. now if you have a query then write us in the comments below.