Since you can boot the Apple Diagnostics, but not a macOS installer (USB or online)....that tells me you must have some sort of hardware issue which is only affecting macOS. The online diagnostics leverages same framework which is used to boot into the online macOS installer....the only difference is the diagnostic does not load macOS & is much more minimal. It is also interesting you cannot boot a macOS USB installer on this Mac, but the installer works for another Mac. Plus the issue just occurred suddenly according to your initial post.
Unfortunately I don't know what the hardware issue could be. Have you tried booting into Safe Mode with the SSD? Safe Mode may even disable some macOS drivers or can utilize a different more basic driver as in the case of a GPU driver.
symkrk wrote:
If I try to wipe the SSD and install Ubuntu, do you think I can install mac any time later?
Usually I would say yes, but Apple seems to be taking the online recovery mode servers offline...at least that is what I'm gathering from Apple's deafening silence to people being unable to utilize recovery mode for some older Macs & installers since people have been reporting issues for over a month now.
If you have a bootable macOS USB installer, or you have access to another compatible Mac in order to create a bootable macOS USB installer, then yes it should be possible.
This all assumes you have no hardware issues which prevents the macOS installer or even macOS from working.
Would a successfull boot from USB install all the necessary partitions on the disk?
macOS installer....no, the user must use Disk Utility to properly erase the SSD.
Ubuntu....I don't recall its default option or behavior since I haven't used Ubuntu in years as I've moved on to another Linux distribution. IIRC, Ubuntu has an option to use the entire drive or to utilize an empty unpartitioned area of a disk (since macOS & Disk Utility doesn't leave any unpartitioned space on the drive you would use the Linux installer to delete the particular partition so you can utilize its space by Linux).
I would recommend practicing by installing Ubuntu to an external drive so you can see first hand how the Ubuntu installer works and the options it offers for preparing the drive. Making a mistake on an external drive won't hurt anything since you can just start over again as long as you don't touch the internal drive. If the Ubuntu installer prompts you for where to install the bootloader, just make sure to select the external drive (it won't really hurt anything if the internal drive is selected, but it allows the external drive to be bootable on its own if moved to another computer (it only installs a folder with a few files onto the hidden ESP/EFI partition so not a big deal).
I wanna use my machine as a computer, not necessarily as a mac, instead of throwing it into the bin.
Linux would definitely allow you to do this.
Just remember you need to learn a bit about Linux and how it works if you want to have a good experience with it. You don't need to learn a lot, just some basics about how it identifies drives & partitions, basic partitioning information since you are already asking questions about installation. Understanding some basics about the distribution's package management behavior (aka software updates, software installation & removal) is also a good idea since this is where many people tend to make mistakes.
I also recommend learning the very basics of using the command line since you will likely need to use it at some point since most online help will have you issuing commands....it is the quickest & easiest way to access information & features since the graphical interface may not provide access (and there are several different GUI interfaces). Never blindly use commands found online since they may be tailored for a very specific case or system, plus many times there can be multiple ways to achieve a task (some are terrible but can work, other ways are better, and some ways may be best or more elegant.... and less risky). Best to examine multiple articles & forum posts before utilizing commands found online & to use your own brain to attempt to understand what those commands do.
You cannot really learn much about Linux until you actually install it and try it....learning really comes just by doing a bit of research when you encounter an issue or a question. If you have the very basics listed, then it makes everything else so much easier if a problem is encountered since you can focus on the issue and not on understanding the behavior of the OS or its tools & utilities. With Ubuntu & Linux Mint, it is possible to use the OS without more than a basic understanding.