How to Fix a MongoDB 4.0.4 Installation Error in Linux

When I first tried installing MongoDB 4.0.4 on my Linux Mint machine (based on Ubuntu 16.04), I followed the official documentation step by step. But instead of a smooth installation, I ran into errors that left me scratching my head. I’ll walk you through exactly what I did, why it failed, how I figured it out, and how you can fix it. By the end, you’ll also have some practice commands to verify MongoDB is working and perform a quick CRUD test.

The Code I First Ran

I started by adding MongoDB’s repo and then tried to install both the latest version and a specific release:

# Add key + repo
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
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
sudo apt-get update

# Install latest
sudo apt-get install -y mongodb-org

# Install a specific point release
sudo apt-get install -y \
  mongodb-org=4.0.4 \
  mongodb-org-server=4.0.4 \
  mongodb-org-shell=4.0.4 \
  mongodb-org-mongos=4.0.4 \
  mongodb-org-tools=4.0.4

But instead of success, I got these errors:

Package mongodb-org is not available...
E: Package 'mongodb-org' has no installation candidate

E: Version '4.0.4' for 'mongodb-org' was not found
...

Why This Failed on My Machine

Here’s what my system looked like:

16.04.1-Ubuntu SMP i686 athlon i686 GNU/Linux (Linux Mint)

Key Problem:

  • i686 = 32-bit.
    MongoDB 4.0 and later are only packaged for 64-bit (amd64). On a 32-bit OS, apt will never find mongodb-org 4.x packages.
  • Repo codename mismatch.
    I added the trusty repo (Ubuntu 14.04), but my Mint version is based on Ubuntu 16.04 xenial. Using the wrong codename makes packages disappear.
  • Forced arch=amd64 on a 32-bit OS.
    My repo line told apt to only look for 64-bit packages, which a 32-bit OS cannot install.

Quick Self Checks

I used these commands to confirm:

# Architecture (i386 means 32-bit)
dpkg --print-architecture

# CPU flags (look for 'lm' = 64-bit support)
lscpu | grep -i "op-mode\|arch\|flags"

# Ubuntu codename
lsb_release -sc

When I saw i386, I knew that was the main blocker.

How to Fix It

Recommended (64-bit OS)

If your CPU supports 64-bit (most Athlons do), install a 64-bit Linux and then:

# Clean up old repo
sudo rm -f /etc/apt/sources.list.d/mongodb-org-4.0.list

# Import MongoDB 4.0 key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \
  --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

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

sudo apt-get update

# Install MongoDB 4.0.4 exactly
sudo apt-get install -y \
  mongodb-org=4.0.4 \
  mongodb-org-server=4.0.4 \
  mongodb-org-shell=4.0.4 \
  mongodb-org-mongos=4.0.4 \
  mongodb-org-tools=4.0.4

# Prevent accidental upgrades
sudo apt-mark hold mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools

Stay on 32-bit (not recommended)

If you must stay on 32-bit Linux, you cannot install official MongoDB 4.x packages. Options:

  • Use the old distro package: sudo apt install mongodb (Outdated, not for production!)
  • Run MongoDB on a 64-bit VM, Docker container, or remote host.

Service Management & CRUD Test

Once MongoDB is installed, I always do a few checks.

Start & verify service

sudo systemctl enable mongod
sudo systemctl start mongod
systemctl status mongod --no-pager
sudo journalctl -u mongod -n 50 --no-pager

Confirm it’s running

ss -lntp | grep 27017
mongo --eval 'db.runCommand({ buildInfo: 1 })'

Configure safely

Edit:

sudo nano /etc/mongod.conf

Ensure it binds to localhost:

net:
  bindIp: 127.0.0.1
  port: 27017

Restart:

sudo systemctl restart mongod

Add an admin user

mongo --eval 'db.getSiblingDB("admin").createUser({user:"admin", pwd:"changeme", roles:["root"]})'

Connect with auth:

mongo -u admin -p changeme --authenticationDatabase admin

CRUD smoke test

mongo --eval 'db.getSiblingDB("play").widgets.insertMany([{name:"A",qty:5},{name:"B",qty:7}])'
mongo --eval 'printjson(db.getSiblingDB("play").widgets.find().toArray())'
mongo --eval 'db.getSiblingDB("play").widgets.updateOne({name:"A"}, {$inc:{qty:1}})'
mongo --eval 'db.getSiblingDB("play").widgets.deleteOne({name:"B"})'

Clean uninstall (if needed)

sudo systemctl stop mongod
sudo apt-get purge -y mongodb-org*
sudo rm -rf /var/log/mongodb /var/lib/mongodb
sudo rm -f /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update

Final Thoughts

When I first saw “Package has no installation candidate”, I thought maybe the repo was down. But after digging deeper, I realized it was my 32-bit OS that caused the real issue. MongoDB 4.x simply doesn’t support 32-bit Linux, and I had also pointed apt at the wrong codename repo.

Related blog posts