In this book, we will install MongoDB 4.2 (Community Edition) on Ubuntu 20.04 (Focal Fossa). It works the same, too, if you are on Ubuntu 19.10 (Eoan Ermine). If you are using other older versions of Ubuntu, such as 14.04 LTS (Trusty Tahr), 16.04 LTS (Xenial Xerus), or 18.04 LTS (Bionic Beaver), please follow the MongoDB Community Edition on Ubuntu link in the previous section. So, let's get started:
- Import the public key from mongodb.org:
$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
You should get an OK in the response.
- Create a list file for MongoDB:
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
- Update all the local packages in your system:
$ sudo apt-get update
- Install the MongoDB packages:
$ sudo apt-get install -y mongodb-org