Apt-get fails while installing mongodb [SOLVED] | Ubuntu latest tricks

If you have also faced the problem like
E: Package 'mongodb-org' has no installation candidate
Then here is the solution for different version of ubuntu:-
Apt-get fails while installing mongodb [SOLVED] | Ubuntu latest tricks

Ubuntu 16.04 or lower and MongoDB 4.0

First, remove any existing repository file for MongoDB.
sudo rm /etc/apt/sources.list.d/mongodb*.list
Next, add the key: (without the key, the repository will not load)
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E52529D4
Now, create a new MongoDB repository list file:
sudo bash -c 'echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.0.list'
Complete the installation with update of repositories then install:
sudo apt update
sudo apt install mongodb-org
Enable the mongod service and start it up:
systemctl enable mongod.service
systemctl start mongod.service
Check your mongodb version:
~$ mongo --version
MongoDB shell version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64
Check if the service is running:
~$ systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-01-21 00:33:51 MST; 7s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 2906 (mongod)
   CGroup: /system.slice/mongod.service
           └─2906 /usr/bin/mongod --config /etc/mongod.conf

Ubuntu 18.04 or newer and MongoDB 4.0


MongoDB 4.0 is shown as stable where 4.1 is as preview for the time being.

First, remove MongoDB from previous if installed:
sudo apt remove --autoremove mongodb-org
Remove any mongodb repo list files:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
Now, add the new key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E52529D4
Add the new repository:
sudo bash -c 'echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.0.list'
Install MongoDB
sudo apt update
sudo apt install mongodb-org
Enable and start the mongod server service:
systemctl enable mongod.service
systemctl start mongod.service
Check your installation:
~$ mongo --version
MongoDB shell version v4.0.3
git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
OpenSSL version: OpenSSL 1.1.0g  2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: x86_64
    target_arch: x86_64
You can also check your service has started:
~$ systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: e
   Active: active (running) since Sun 2018-10-07 12:33:46 MDT; 2min 34s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 5573 (mongod)
   CGroup: /system.slice/mongod.service
           └─5573 /usr/bin/mongod --config /etc/mongod.conf
Thanks.........
Apt-get fails while installing mongodb [SOLVED] | Ubuntu latest tricks Apt-get fails while installing mongodb [SOLVED] | Ubuntu latest tricks Reviewed by Sumit Bishnoi on December 10, 2019 Rating: 5

No comments:

Powered by Blogger.