You should use the latest Long-Term Support (LTS) version of Ubuntu for Magento. Currently, Ubuntu 20.04 LTS is the latest version that is guaranteed to receive free maintenance and security updates until April 2025, with an option to extend support up to April 2030.