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.
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
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
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:
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
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 –
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
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
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:
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
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.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/223815.html