1. Installing NodeJS
First of all, we'll need to setup the most important and key program behind every scene ie NodeJS. NodeJS is pretty easy to install in linux machine running Ubuntu or CentOS.
On Ubuntu 15.04
We'll first need to update our local repository index in order to retrieve required updates of the package lists available in the repository. To do so, we'll need to run the following apt-get command.
$ sudo apt-get update $ sudo apt-get install gcc g++ make build-essential libssl-dev git
On CentOS 7
In the machine running CentOS 7, we'll need to run yum update in order to update every packages installed in the system. We'll need to run the command under root or sudo access.
$ sudo yum update
After that, we'll install the essential development packages need to compile our NodeJS.
$ sudo yum install gcc gcc-c++ git
Downloading and Extracting
After the dependencies are installed, we'll download the latest release of NodeJS from the official download server using wget.
$ wget https://nodejs.org/download/release/node-latest.tar.gz -O /tmp/node-latest.tar.gz --2015-11-22 05:01:17-- https://nodejs.org/download/release/node-latest.tar.gz Resolving nodejs.org (nodejs.org)... 2400:cb00:2048:1::6814:172e, 2400:cb00:2048:1::6814:162e, 22.214.171.124, ... Connecting to nodejs.org (nodejs.org)|2400:cb00:2048:1::6814:172e|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 22470092 (21M) [application/gzip] Saving to: '/tmp/node-latest.tar.gz' /tmp/node-latest.tar. 100%[=========================>] 21.43M 3.77MB/s in 6.9s 2015-11-22 05:01:25 (3.10 MB/s) - '/tmp/node-latest.tar.gz' saved [22470092/22470092] $ tar -xvzf /tmp/node-latest.tar.gz
Compiling and Installing
Once the extraction of the tarball is completed, we'll continue further for the compilation of the source code of NodeJS. To do so, first, we'll need to check if every development dependencies are installed or not using ./configure command. Then, we'll compile the source code using make command which will take a lot time to finish the compilation and finally install the binary in our machine using make install command.
$ cd node-v5.1.0 $ ./configure $ make $ sudo make install
After the installation is complete, we'll gonna check if node was successfully installed or not by asking node its version.
$ node --version v5.1.0
Common Error and Fixes in CentOS 7
On running node commands with sudo, we may get error sudo: npm: command not found on our shell. To fix that, we'll need to run the following commands in a terminal or console.
$ sudo ln -s /usr/local/bin/node /usr/bin/node $ sudo ln -s /usr/local/lib/node /usr/lib/node $ sudo ln -s /usr/local/bin/npm /usr/bin/npm $ sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
2. Installing MongoDB
Next, we'll install MongoDB, a free and open source document-oriented database server which is also know as NoSQL database server. It is designed for handling document-oriented storage and stores data in JSON-like documents with dynamic schema known as BSON which makes the integration of data in certain types of applications easier and faster. To install MongoDB, we'll need to follow the below setups with respect to the distribution of linux we are running.
On Ubuntu 15.04
We'll now need to add the MongoDB official repository to our source list so that we can fetch the package list and path of it. To do so, we'll need to run the following command in a terminal or console.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 $ sudo echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
After that, we'll gonna update our local repository index with that of the mongodb repository using apt-get command.
$ sudo apt-get update
Now, we'll need to run the following command in order to install it in our Ubuntu machine.
$ sudo apt-get install -y mongodb-org
On CentOS 7
In the machine running CentOS 7, we'll gonna install the latest stable mongodb release ie version 3.0 using yum package manager. To do so, first we'll need to add the repository in our operating system which can be done using a text editor.
$ sudo nano /etc/yum.repos.d/mongodb-org-3.0.repo
After opening the file with a text editor, we'll need to append the file with the following lines of configurations.
[mongodb-org-3.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/ gpgcheck=0 enabled=1
Then, we'll save the file and exit the text editor. Next, we'll install the mongodb using yum package manager by running the following command.
$ sudo yum install mongodb-org
3. Starting and Enabling MongoDB
After our MongoDB is installed, we'll now gonna start our MongoDB server and make it run automatically in every boot. To do so, we'll need to run the following commands.
As Systemd is the default service/daemon, process manager replacing SysVinit in Ubuntu 15.04 and CentOS 7, we'll gonna run the following command in order to start the mongodb server.
$ sudo systemctl start mongod
Now, to enable mongod to start in every system boot, we'll need to execute the following command.
$ sudo systemctl enable mongod
4. Installing Bower
As we have got Nodejs and NPM installed, we'll now gonna install Bower package manager in our Linux machine. Bower package manager manages front-end packages for our web application. It provides hooks to facilitate using packages in our tools and workflows. It fetches and installs necessary stuffs from all over making everything frameworks, libraries, assets, utilities, and rainbows managed for the developer. To install bower, we'll need to run the following command.
$ sudo npm install -g bower /usr/local/bin/bower -> /usr/local/lib/node_modules/bower/bin/bower /usr/local/lib └── firstname.lastname@example.org
5. Installing Gulp
$ sudo npm install -g gulp
6. Installing mean-cli
Now, we'll install the mean-cli package using npm. This will add mean command to our system which will let us to interact (install, manage, update, etc) our Mean based application. To install it, we'll need to run the following npm command.
$ sudo npm install -g mean-cli
7. Generating MEAN Application
The application generator will ask us some questions about our new application and will create a fresh copy of a MEAN.IO application in the working directory. To do so, we'll need to run the following yo command into our project directory.
$ mean init test-app
Next, we'll install all the dependencies required to run our mean application by running the following command.
$ cd test-app && npm install email@example.com postinstall /home/arun/test-app > node tools/scripts/postinstall.js $ bower install
8. Running the Application
After the MEAN application has been generated, we'll now finally run our newly created application. To run our application, we'll need to execute gulp command into our MEAN application directory.
Now, as our application is running, we should be able to browse our web application. To do so, we'll point our favorite web browser to the server running the application. As gulp runs the applications under port 3000 by default so, we'll point our browser to http://ip-address:3000 or http://domain.com:3000.
If we wanna assign a port for our application, we can simply run the following command.
$ export PORT=3001 && gulp
Finally, we have successfully setup MEAN.IO stack for deploying our MEAN based application on our machine running CentOS 7 and Ubuntu 15.04. It is an awesome framework for an easy starting point with MongoDB, Node.js, Express, and AngularJS based applications. It a complete replacement for our traditional LAMP Stack. It helps us to save a long time required to build our custom MEAN stack as its pretty easy with just few commands to setup a complete MEAN stack. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you !