to get Ubuntu onto the pi you need to take the SD card out, plug it into your computer with the [raspberry pi imager](
https://www.raspberrypi.com/software/ ) and select the correct options. it will then install Ubuntu for you but unfortunately yes this will clear the current os and any progress you've made on it