How to Install MongoDB 3.4 on Ubuntu 16.04/14.04 and Debian 8/7

MongoDB (named from “huMONGOus“) is a full flexible index support and rich queries database. Mongodb is a NoSQL database. MongoDB provides large media storage with GridFS. Click here for more details about this version of MongoDB.
install mongodb
This tutorial will help you to install MongoDB 3.4 Production Release on Ubuntu 16.04 LTS (Xenial) 14.04 LTS (trusty) and Debian 8 and 7 systems.

Adding Apt Repository

First import public key of MongoDB apt repository in our system using the following command.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 
Lets add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb-3.4.list.
For Ubuntu 14.04 & 12.04:
$ echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list 
For Ubuntu 16.04:
$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list 
For Debian 8 & 7:
$ echo "deb http://repo.mongodb.org/apt/debian "$(lsb_release -sc)"/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list 

Install MongoDB

After adding required APT repositories, use following commands to install MongoDB on your systems. It will also install all dependent packages required for MongoDB.
$ sudo apt-get update $ sudo apt-get install mongodb-org 
If you want to install any specific version of MontoDB, define the version number like below
$ apt-get install mongodb-org=3.4.1 mongodb-org-server=3.4.1 mongodb-org-shell=3.4.1 mongodb-org-mongos=3.4.1 mongodb-org-tools=3.4.10 

Start MongoDB Service

After installation, MongoDB will start automatically. To start or stop MongoDB use init script. Below are the example commands to do.
$ sudo service mongod start $ sudo service mongod stop 

Verify MongoDB Installation

Finally, use the below command to check installed MongoDB version on your system.
rahul@tecadmin:~$ mongod --version   db version v3.4.1 git version: 5e103c4f5583e2566a45d740225dc250baacfbd7 OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016 allocator: tcmalloc modules: none build environment:     distmod: ubuntu1604     distarch: x86_64     target_arch: x86_64 
Also, connect MongoDB using the command line and execute some test commands for checking proper working.
ubuntu@tecadmin:~$ mongo  > use mydb;  > db.test.save( { tecadmin: 100 } )  > db.test.find()    { "_id" : ObjectId("52b0dc8285f8a8071cbb5daf"), "tecadmin" : 100 } 

Thanks for Visit Here

Comments