STEP 1: Enter the GPK code in the terminal
$ sudo apt-key adv--keyserver hkp://keyserver.ubuntu.com:80--recv 9da31620334bd75d9dcb49f368818c72e52529d4
STEP 2: Add a MongoDB source
Ubuntu 18.04 LTS:
$ echo "Deb [ARCH=AMD64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Multiverse" | sudo tee/etc/apt/sources.list.d/mongodb.list
Ubuntu 16.04 LTS:
$ 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.list
STEP 3:install MongoDB Server
$ sudo apt update
$ sudo apt install mongodb-org
You can also install the specified version of MongoDB directly
$ sudo apt install mongodb-org=4.0.1 mongodb-org-server=4.0.1 mongodb-org-shell=4.0.1 mongodb-org-mongos=4.0.1 mongodb-org-tools=4.0.1
STEP 4: Management of the MONGODB server
$ sudo systemctl enable Mongod
$ sudo systemctl start Mongod
STEP 5: Verify mongoDB4.0
$ Mongod--version
DB version v4.0.1 git VERSION:54F1582FC6EB01DE4D4C42F26FC133E623F065FB
OpenSSL Version:openssl 1.1.0h Mar 2018
Allocator:tcmalloc
Modules:none
Build Environment:
distmod:ubuntu1804
Distarch:x86_64
Target_arch:x86_64
Step 6: Build a library test
$ MONGO
> Use mydb;
> Db.test.save ({tecadmin:100})
> Db.test.find ()
{"_id": ObjectId ("52b0dc8285f8a8071cbb5daf"), "Tecadmin": 100}
ubuntu18.04 Installing MongoDB 4.0