Install MEAN.JS Stack in CentOS 7
We have posted a step by step guide about MEAN.JS installation in Ubuntu 14.04 LTS server in our previous tutorial. To install MEAN.JS stack in Ubuntu, refer the following link.
Today, in this tutorial, we will see how to install MEAN.JS stack in CentOS 7 64 bit server. This guide might work on other RPM based systems such as RHEL 7, Scientific Linux 7, and Fedora etc.
MongoDB is not available in default repositories. So, let us add MongoDB official repository, and install it.
Log in as root user, and run the following command to import MongoDB repository GPG key:
rpm --import https://www.mongodb.org/static/pgp/server-3.2.asc
Create a new repository for MongoDB repository:
Add the following lines:
[mongodb-org-3.2] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/ gpgcheck=1 enabled=1
Save and close the file.
Update the software repository lists:
Finally install MongoDB with required prerequisites in CentOS 7 with the following command:
yum install mongodb-org mongodb-org-server gcc gcc-c++ git make
Allow MongoDB relevant ports via Firewall using command:
firewall-cmd --permanent --add-port=27017/tcp
firewall-cmd --permanent --add-port=3000/tcp
Please note that, you need to allow port 3000 via Firewall/Router in-order to access MEAN stack test page from a remote system.
Restart firewalld service:
Enable access to the MongoDB ports (e.g. 27017) for SELinux:
semanage port -a -t mongod_port_t -p tcp 27017
If you see semanage command not found error, check the following guide.
Start MongoDB service using command:
systemctl start mongod
Enable MongoDB service at boot:
systemctl enable mongod
You can check whether MongoDB service is running or not using command:
systemctl status mongod
mongod.service - SYSV: Mongo is a scalable, document-oriented database. Loaded: loaded (/etc/rc.d/init.d/mongod) Active: active (running) since Wed 2016-03-30 13:59:57 IST; 23s ago Main PID: 2781 (mongod) CGroup: /system.slice/mongod.service └─2781 /usr/bin/mongod -f /etc/mongod.conf Mar 30 13:59:55 server1.ostechnix.local systemd: Starting SYSV: Mongo is a... Mar 30 13:59:55 server1.ostechnix.local runuser: pam_unix(runuser:sessi... Mar 30 13:59:57 server1.ostechnix.local mongod: Starting mongod: [ OK ] Mar 30 13:59:57 server1.ostechnix.local systemd: Started SYSV: Mongo is a ... Hint: Some lines were ellipsized, use -l to show in full.
Now, let us install Node.js,
Add Node.js repository depending upon the version you want to use.
For Node.js v4:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
For Node.js v5:
curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
For Node.js 0.10:
curl --silent --location https://rpm.nodesource.com/setup | bash -
Then, install Node.js using command:
yum install -y nodejs
The above command will install nodejs and npm. You don’t need to install npm separately. Npm or Node.js package manager is used to install additional packages required for installing MEAN stack.
To check the Node.js version run the following command:
After installing, MongoDB, and Node.js, we need to install the other required components such as Bower, Frunt, and Gulp for MEAN.js stack.
Install Bower package manager
Bower is a package manager used by MEAN.JS stack to manage front-end packages.
To install Bower, run the following command:
npm install -g bower
/usr/bin/bower -> /usr/lib/node_modules/bower/bin/bower /usr/lib └── email@example.com
Install Grunt Task Runner
Grunt Task Runner is used to to automate the development process.
To install Grunt, run:
npm install -g grunt-cli
/usr/bin/grunt -> /usr/lib/node_modules/grunt-cli/bin/grunt /usr/lib └─┬ firstname.lastname@example.org ├─┬ email@example.com │ └─┬ firstname.lastname@example.org │ ├─┬ email@example.com │ │ └── firstname.lastname@example.org │ ├── email@example.com │ ├─┬ firstname.lastname@example.org │ │ └─┬ email@example.com │ │ ├── firstname.lastname@example.org │ │ └── email@example.com │ ├── firstname.lastname@example.org │ └── email@example.com ├─┬ firstname.lastname@example.org │ └── email@example.com └── firstname.lastname@example.org
Install Gulp Task Runner (Optional)
This is optional. You can use Gulp instead of Grunt.
To install Gulp Task Runner, run the following command:
sudo npm install -g gulp
We have installed all required prerequisites. Now, let us deploy MEAN.JS stack.
Download and Install MEAN.JS Stack
Git clone the MEAN.JS repository with command:
git clone https://github.com/meanjs/mean.git meanjs
Cloning into 'meanjs'... remote: Counting objects: 8596, done. remote: Compressing objects: 100% (12/12), done. remote: Total 8596 (delta 3), reused 0 (delta 0), pack-reused 8584 Receiving objects: 100% (8596/8596), 2.62 MiB | 140.00 KiB/s, done. Resolving deltas: 100% (4322/4322), done. Checking connectivity... done.
The above command will clone the latest version of the MEAN.JS repository to a meanjs folder.
Go to the meanjs folder:
Run the following command to install the Node.js dependencies required for testing and running our application.
This will take some time. Please be patient.
Once all dependencies are installed, run the following command to install all the front-end modules needed for the application.
bower --allow-root --config.interactive=false install
MEAN.JS stack has been installed. We can now able to start a sample application using Grunt task runner. To do so, run the following command:
In case the above command for some reason, use –force flag as shown below.
After a few seconds, you will see a message like below. This means MEAN.JS stack is working.
[...] -- MEAN.JS - Development Environment Environment: development Server: http://0.0.0.0:3000 Database: mongodb://localhost/mean-dev App version: 0.5.0-beta MEAN.JS version: 0.5.0-beta [...]
To verify, open up the browser and navigate to http://localhost:3000 or http://IP-Address:3000/. You should see a screen something like below.
Congratulations! MEAN.JS stack is ready to start building web applications.
For further details, I recommend you to refer MEAN.JS stack official documentation.
That’s all for now folks. Hope this tutorial will help you to setup MEAN.JS stack.
If you find this tutorial useful, please share it on your social networks and support OSTechNix.