MongoDB: Install Client – Mongo Shell – Ubuntu, CentOS

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 it is enough to install MongoDB client only, without MongoDB itself.

From the following article you will find out how to install the latest (or specific) version of mongo shell on Ubuntu and CentOS.

Specific Release: To install mongo shell from a specific release, check the official MongoDB repository and appropriately change the names and repo URLs.

Cool Tip: How to connect to remote MongoDB server from the command line using mongo shell! Read More →

Install Mongo Shell on Ubuntu

Add the official MongoDB repository:

# Ubuntu-18.04:
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" \
    | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

# Ubuntu-16.04:
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" \
    | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

# Ubuntu-14.04:
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/4.0 multiverse" \
    | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Import the public key:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \
    --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Install the latest version of mongo shell:

$ sudo apt-get update
$ sudo apt-get install -y mongodb-org-shell

To install a specific version of mongo shell, run:

$ sudo apt-get install -y mongodb-org-shell=4.0.3

Install Mongo Shell on CentOS

Add the official MongoDB repository:

$ echo '[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' \
    | sudo tee /etc/yum.repos.d/mongodb-org-4.0.repo

Import the public key:

$ sudo rpm --import https://www.mongodb.org/static/pgp/server-4.0.asc

Install the latest version of mongo shell:

$ sudo yum install -y mongodb-org-shell

To install a specific version of mongo shell, run:

$ sudo yum install -y mongodb-org-shell-4.0.3

For more details check the official MongoDB installation guide.

Leave a Reply