MEAN is a free and open-source JavaScript software stack. MEAN stack is named using the first letter of its four components MongoDB, Express.js, AngularJS and Node.js. Because all four components of MEAN stack support JavaScript therefore MEAN stack is used for both server-side and client-side execution environments for building dynamic websites and web applications using JavaScript.
In this article, we are installing MEAN stack on CentOS 7 server. Here, we are not emphasizing on the developments and deployments of JavaScript based web applications on MEAN stack. Therefore, if you want to explore MEAN stack in depth, then you should read MEAN Web Development by Packt Publishing.
Table of Contents:
- Environment Specification
- Installing MEAN Stack Prerequisite Packages
- Installing MongoDB 4 on CentOS 7
- Installing Node.js 10 on CentOS 7
- Installing Yarn Package Manager on CentOS 7
- Installing Gulp Task Scheduler on CentOS 7
- Installing MEAN Stack on CentOS 7
- Testing MEAN Stack on CentOS 7
Environment Specification:
We have provisioned a CentOS 7 virtual machine with following specifications.
- CPU – 3.4 Ghz (Single Core)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – CentOS 7.6
- Hostname – nodejs-01.example.com
- IP Address – 192.168.116.190 /24
Installing MEAN Stack Prerequisite Packages:
Connect with nodejs-01.example.com using ssh as root user.
These packages are required by various components of MEAN stack; therefore, we are installing them in one go using yum command.
# yum install -y gcc-c++ make git
Installing MongoDB 4 on CentOS 7:
MongoDB is not available in standard yum repositories. Therefore, we have to install MongoDB official yum repository on our Linux server and then we will be able to install MongoDB database.
Create a yum repository file in /etc/yum.repos.d directory.
# vi /etc/yum.repos.d/mongodb.repo
and add following configurations therein.
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
Build cache for MongoDB yum repository.
# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp3.isra.edu.pk
* extras: ftp3.isra.edu.pk
* updates: ftp3.isra.edu.pk
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
mongodb-org-4.0 | 2.5 kB 00:00
updates | 3.4 kB 00:00
mongodb-org-4.0/7/primary_db | 53 kB 00:00
Metadata Cache Created
Install MongoDB 4 on our CentOS 7 server using yum command.
# yum install -y mongodb-org
MongoDB database service ‘mongod.service’ is automatically enabled by the installer. We are only required to start MongoDB service once.
# systemctl start mongod.service
MongoDB 4 has been installed on our CentOS 7 server.
Installing Node.js 10 on CentOS 7:
Node.js is not available in standard yum repositories. Therefore, we have to install Node.js official yum repository then we will be able to install Node.js.
Node.js provides a binary installer that installs Node.js yum repository. Therefore, download and execute that binary file as follows.
# curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash -
## Installing the NodeSource Node.js 10.x repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_10.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.8FUOG96Pkq' 'https://rpm.nodesource.com/pub_10.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.8FUOG96Pkq'
## Cleaning up...
+ rm -f '/tmp/tmp.8FUOG96Pkq'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `sudo yum install -y nodejs` to install Node.js 10.x and npm.
## You may also need development tools to build native addons:
sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install yarn
Now, we have installed Node.js yum repository. Note down the commands to install Yarn package manager on CentOS 7. We will use these commands to install Yarn package manager later in this article.
Install Node.js 10 on our Linux server using yum command.
# yum install -y nodejs
Verify version of Node.js and relevant libraries.
# npm version
{ npm: '6.9.0',
ares: '1.15.0',
brotli: '1.0.7',
cldr: '35.1',
http_parser: '2.8.0',
icu: '64.2',
modules: '64',
napi: '4',
nghttp2: '1.34.0',
node: '10.16.0',
openssl: '1.1.1b',
tz: '2019a',
unicode: '12.1',
uv: '1.28.0',
v8: '6.8.275.32-node.52',
zlib: '1.2.11' }
Node.js 10 has been installed on our CentOS 7 server.
npm, the Node.js package manager, is also installed with Node.js. We can use npm to install rest of the components of MEAN stack.
Installing Yarn Package Manager on CentOS 7:
Yarn is a package manager for front-end applications. It is a replacement of Bower package manager, that was used in previous versions of MEAN stack.
Install Yarn official yum repository as follows.
# curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
[yarn]
name=Yarn Repository
baseurl=https://dl.yarnpkg.com/rpm/
enabled=1
gpgcheck=1
gpgkey=https://dl.yarnpkg.com/rpm/pubkey.gpg
Install Yarn using yum command.
# yum install -y yarn
Installing Gulp Task Scheduler on CentOS 7:
Gulp is a JavaScript task scheduler. Gulp is required by Node.js and we can install it using npm command.
# npm install -g gulp
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/gulp/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ gulp@4.0.2
added 314 packages from 217 contributors in 67.397s
Installing MEAN Stack on CentOS 7:
Download latest version of MEAN stack from GitHub using git command.
# cd /tmp # git clone https://github.com/linnovate/mean Cloning into 'mean'... remote: Enumerating objects: 16743, done. remote: Total 16743 (delta 0), reused 0 (delta 0), pack-reused 16743 Receiving objects: 100% (16743/16743), 8.04 MiB | 415.00 KiB/s, done. Resolving deltas: 100% (9154/9154), done.
Switch to /tmp/mean directory and install MEAN stack on our CentOS 7 server using npm command.
# cd /tmp/mean # npm install npm WARN deprecated @angular/http@6.1.10: Switch to @angular/common/http - see https://angular.io/guide/http npm WARN deprecated core-js@2.5.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2. npm WARN deprecated joi@13.7.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial). npm WARN deprecated istanbul@0.4.5: This module is no longer maintained, try this instead: npm WARN deprecated npm i nyc npm WARN deprecated Visit https://istanbul.js.org/integrations for other alternatives. npm WARN deprecated topo@3.0.3: This module has moved and is now available at @hapi/topo. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues. npm WARN deprecated hoek@5.0.4: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial). npm WARN deprecated circular-json@0.5.9: CircularJSON is in maintenance only, flatted is its successor. npm WARN deprecated hoek@6.1.3: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues. > node-sass@4.12.0 install /tmp/mean/node_modules/node-sass > node scripts/install.js Downloading binary from https://github.com/sass/node-sass/releases/download/v4.12.0/linux-x64-64_binding.node Download complete ] - : Binary saved to /tmp/mean/node_modules/node-sass/vendor/linux-x64-64/binding.node Caching binary to /root/.npm/node-sass/4.12.0/linux-x64-64_binding.node > bcrypt@3.0.6 install /tmp/mean/node_modules/bcrypt > node-pre-gyp install --fallback-to-build node-pre-gyp WARN Using request for node-pre-gyp https download [bcrypt] Success: "/tmp/mean/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote > node-sass@4.12.0 postinstall /tmp/mean/node_modules/node-sass > node scripts/build.js Binary found at /tmp/mean/node_modules/node-sass/vendor/linux-x64-64/binding.node Testing binary Binary is fine > nodemon@1.19.1 postinstall /tmp/mean/node_modules/nodemon > node bin/postinstall || exit 0 Love nodemon? You can now support the project via the open collective: > https://opencollective.com/nodemon/donate npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN karma-jasmine-html-reporter@1.1.0 requires a peer of jasmine@>=3 but none is installed. You must install peer dependencies yourself. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) added 1352 packages from 1431 contributors and audited 47449 packages in 233.363s found 2 low severity vulnerabilities run `npm audit fix` to fix them, or `npm audit` for details
Installer found some known security vulnerabilities in packages. We are fixing them as proposed by the above command.
# npm audit fix
npm WARN karma-jasmine-html-reporter@1.1.0 requires a peer of jasmine@>=3 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
up to date in 10.718s
fixed 0 of 2 vulnerabilities in 47449 scanned packages
2 package updates for 2 vulns involved breaking changes
(use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)
Not all security vulnerabilities can be automatically fixed by audit command. We are required to review and fixed some of them manually.
Allow MEAN stack service port in Linux firewall.
# firewall-cmd --permanent --add-port=4040/tcp success # firewall-cmd --reload success
Check installed packages using following command.
# npm list --depth=0
Testing MEAN Stack on CentOS 7:
To test our MEAN stack configurations, we are running a sample application as follows.
# cd /tmp/mean # cp .env.example .env # npm start > mean@2.0.2 start /tmp/mean > concurrently -c "yellow.bold,green.bold" -n "SERVER,BUILD" "nodemon server" "ng build --watch" [SERVER] [nodemon] 1.19.1 [SERVER] [nodemon] to restart at any time, enter `rs` [SERVER] [nodemon] watching: *.* [SERVER] [nodemon] starting `node server` [SERVER] ../../dist/ [SERVER] (node:7803) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. [SERVER] server started on port 4040 (development) [SERVER] (node:7803) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. [BUILD] [BUILD] Date: 2019-07-31T16:21:26.793Z [BUILD] Hash: e51cc472579f782c888b [BUILD] Time: 28886ms [BUILD] chunk {main} main.js, main.js.map (main) 78.5 kB [initial] [rendered] [BUILD] chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 241 kB [initial] [rendered] [BUILD] chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered] [BUILD] chunk {styles} styles.js, styles.js.map (styles) 102 kB [initial] [rendered] [BUILD] chunk {vendor} vendor.js, vendor.js.map (vendor) 7.01 MB [initial] [rendered] [SERVER] [nodemon] restarting due to changes... [SERVER] [nodemon] restarting due to changes... [SERVER] [nodemon] restarting due to changes... [SERVER] [nodemon] restarting due to changes... [SERVER] [nodemon] restarting due to changes... [SERVER] [nodemon] starting `node server` [SERVER] ../../dist/ [SERVER] (node:7838) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. [SERVER] server started on port 4040 (development) [SERVER] (node:7838) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
Open URL http://nodejs-01.example.com:4040 in a web browser.
MEAN Stack is successfully installed on CentOS 7 server.
very nice Article!
ReplyDeleteCould you please write on next steps to learn mean stack ?
Thanks for appreciation.
DeleteI honor your request but this blog is about system administration of Linux servers.
If you want to learn MEAN stack then please read the recommended book in the above article.