-->

DEVOPSZONES

  • Recent blogs

    MongoDB: Install Mongo Client and Mongo Shell in Ubuntu, CentOS

    MongoDB: Install Mongo Client and Mongo Shell in Ubuntu, CentOS


    mongodb

    The MongoDB client, also known as mongo shell, is a command line interface to MongoDB. The mongo shell is included in MongoDB package, but to connect to MongoDB we only need to install MongoDB client.

    You need to run all these commands as root or use sudo.
    For Installing MongoDB 4, Please refer this document.

    Install Mongo Shell and Client tools on Ubuntu


    Import the public key :

    From a terminal, issue the following command to import the MongoDB public GPG Key.

    wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc |  apt-key add -


    The operation should respond with an OK.


    However, if you receive an error indicating that gnupg is not installed, you can:

    Install gnupg and its required libraries using the following command:

    apt-get install gnupg


    Create a list file for MongoDB.

    Create the list file /etc/apt/sources.list.d/mongodb-org-4.2.list for your version of Ubuntu.

    echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" |  tee /etc/apt/sources.list.d/mongodb-org-4.2.list


    Update package database.

    Issue the following command to reload the local package database:

     apt-get update

     root@tomcat-deployment:/etc/apt/sources.list.d# apt-get update
    Hit:1 http://security.debian.org/debian-security buster/updates InRelease
    Ign:2 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 InRelease
    Get:3 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 Release [3951 B]
    Hit:4 http://deb.debian.org/debian buster InRelease


     Install Mongo tools on Ubuntu

     apt-get install mongodb-org-tools

     root@tomcat-deployment:/etc/apt/sources.list.d# apt-get install mongodb-org-tools
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
      mongodb-org-tools
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 57.0 MB of archives.

     Install Mongo shell on Ubuntu

     apt-get install -y mongodb-org-shell

    root@tomcat-deployment:/etc/apt/sources.list.d# apt-get install -y mongodb-org-shell
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
      mongodb-org-shell
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    MongoDB

    Check the mongo tool:

     mongo --version

    root@tomcat-deployment:/etc/apt/sources.list.d# mongo --version
    MongoDB shell version v4.2.6
    git version: 20364840b8f1af16917e4c23c1b5f5efd8b352f8
    OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019
    allocator: tcmalloc
    modules: none
    build environment:
        distmod: ubuntu1804
        distarch: x86_64
        target_arch: x86_64
    root@tomcat-deployment:/etc/apt/sources.list.d#



    Install Mongo Shell and Client tools on CentOS


    Create a /etc/yum.repos.d/mongodb-org-4.2.repo file.


    [mongodb-org-4.2]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

    Install the latest version of mongo shell:

     yum install -y  mongodb-org-shell mongodb-org-tools

     Check the mongo tool:

     mongo --version


    Useful MongoDB Articles:

    No comments