Here's one way, using LXD Containers (this is how I do it). This is not the only way, and what might work best for you may be different than what works best for me. I'm moderately skilled at this stuff; coming at this new to containers, networking, package management, and systemd would take a couple days of learning.
Containers use Kernel features to behave quite like a Virtual Machine (VM) - a container feels like a separate machine, but with surprisingly little overhead resource cost. You can use containers to isolate different versions of applications (like Java) without affecting your host system, and to host different network services. Containers are not real VMs, and containers are not perfect...but they can be very handy.
Planning. You will need around 15GB (total) for the containers.
Install and set up the
lxd snap. Very good tutorial and example.
Create a test container. Take a couple minutes to practice starting and stopping it, creating and destroying it, figuring out it's IP address, and how to get shell access within the container. Also figure out how to autostart a container at host boot.
Create two containers. Get shell access inside each. Install the appropriate Java and Minecraft Server into each container. Depending upon the version of Java you need, your containers might be using two different releases of Ubuntu! Install whatever release of Ubuntu includes the correct version of Java that you need. DON'T install the newest Ubuntu and then try to mangle the system to make a different Java fit. DON'T install Java from a non-Ubuntu source.
[OPTIONAL] Edit the LXD networking profile to get IP addresses from your router instead of a host-internal NAT. This means you only need to port forward once (at the router) and keeps your network simpler. Each container will have a separate IP address. Set up the port forwarding on your router for both containers.
Set up systemd services within each container to start and stop the minecraft server. This will start the minecraft server at container-start (boot), and gracefully stop the server at container-stop (shutdown). I prefer this over the typical
screen hacks. All Minecraft Server output is logged anyway, so you can read it anytime.
Finally, figure out how you want to backup your Minecraft worlds. You can simply export a copy of the entire container to whatever your backup scheme is (warning: it's big). Or your can use the
lxc pull command to merely grab the /home/minecraft directory where all the data is.
NOTE: Lots of folks make mistakes with their first container. That's okay. Keep notes on what you did and why so you can maintain it, improve it, and remake it better next time.
That seems like a lot of setup. However, it has a lot of benefits: Each Minecraft Server is fully sandboxed from the host system and from the other server. Different IP addresses, different everything...but easy control, monitoring, and troubleshooting for you. This setup uses built-in features of Ubuntu: Package management, automatic security upgrades, systemd control and monitoring.