Here are some easy steps on how to install MEAN stack on Linux machine running CentOS 7
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.
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 $ 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.
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
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.
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
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
$ sudo npm install -g gulp
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
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
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 !