Proxmox: MongoDB 5.0+ requires a CPU with AVX support

This error is caused by running MongoDB 5.0+ on a VM using a KVM64 CPU type. The fix for this is to switch your CPU type to host (if your host CPU supports AVX), or use version 4.4.18 of MongoDB instead.

I ran into this error when working on the SupeTokens example. If you want to learn more about how to use SuperTokens to secure your web apps, check it out.

What is AVX?

AVX stands for Advanced Vector Extensions. They are additional instructions added to the x86 instruction set that make it possible to do parallel calculations on multiple floating point numbers with one instruction. Apparently, MongoDB 5.0+ uses these features.

Problem: you’re running the latest MongoDB on a KVM64 VM

When creating a VM in Proxmox, the default CPU type is KVM64.

Unfortunately, this CPU type does not support AVX, which means if you’re using the latest MongoDB image from DockerHub like this:

     - PROD=${PROD}
 mongodb:
   image: mongo
 supertokens:
   image: supertokens/supertokens-mongodb
YAML

You’ll get this “warning” which is actually an error, because it crashes MongoDB:

WARNING: MongoDB 5.0+ requires a CPU with AVX support, and your current system does not appear to have that!
  see https://jira.mongodb.org/browse/SERVER-54407
  see also https://www.mongodb.com/community/forums/t/mongodb-5-0-cpu-intel-g4650-compatibility/116610/2
  see also https://github.com/docker-library/mongo/issues/485#issuecomment-891991814

Solution 1: use “host” as the CPU type for your VM

Your host’s CPU most likely supports AVX. Both Intel and AMD CPUs have supported AVX since 2011. So, unless you’re running on very old hardware, simply changing your CPU type to host is the recommended solution to this problem.

To change this, shut down your VM, then go to the hardware tab, and change your processor type to host like this:

If you’re still having the error occur after booting your VM back up, you might need to just use an older version of MongoDB.

Solution 2: use an older version of MongoDB

If your underlying CPU for your Proxmox host is really old and doesn’t support AVX, you might need to just use an older version of MongoDB. This is typically not recommended, as older versions of software may contain security holes that are patched in later versions. Only do this as a last resort.

The latest version of MongoDB that doesn’t require AVX support is 4.4.18. Update your docker-compose file to use that version like this:

      - PROD=${PROD}
  mongodb:
    image: mongo:4.4.18
  supertokens:
    image: supertokens/supertokens-mongodb
YAML

And now you should have no issues running MongoDB in a Proxmox VM.

Conclusion

After version 5.0 of MongoDB, it started requiring Advanced Vector Extensions (AVX) to run. This isn’t a problem if running on bare metal with a CPU made in the last decade, but it is a problem if you’re running it in a Proxmox VM with the default KVM64 CPU type. To fix the error, just make your CPU type “host” (if your host CPU does actually support AVX) or use an older version of MongoDB. The newest version of MongoDB that doesn’t require AVX support is 4.4.18.