Updates can only be done for the next major version. If you want do update from 6 to 8, you need to do it in two steps.

To update a local mongodb you have to do the following steps:

  1. Check/Set Feature Compatibility Version: Upgrade from 7 to 8
  2. Stop mongod: sudo systemctl stop mongod
  3. Uninstall mongod: sudo apt-get purge "mongodb-org*"
  4. Install new version: Install Version 8
  5. Check Version: mongod -version
  6. Start service: sudo systemctl start mongod