Are you able to boot into Recovery Mode (Command + R) or better yet Internet Recovery Mode (Command + Option + R)? This part should still be possible AFAIK. I do know that actually selecting the "Install macOS" option once you reach the recovery mode screen is where the trouble usually begins since Apple has been having issues with this part over the past year (we actually thought Apple disabled those older online installers), but we do still hear about issues from time to time for that stage of the process.
It really helps to know exactly at what stage the process fails and the exact error message you encounter. Booting into Internet Recovery Mode requires a good network connection, otherwise you will encounter a large negative error code (could by your home network, router, modem, or your ISP, or local Internet, once in a while Apple's servers although the latter is rare).
Otherwise you will need access to another Mac which is compatible with an OS your old iMac can use in order to create a bootable macOS USB installer. For example, if your iMac is compatible with macOS 10.11 El Capitan, then you generally have these options for another compatible Mac (there are some exceptions):
- For macOS 10.13 -- a Mac from Late-2009 to 2018
- For macOS 10.11 -- a Mac from 2007 to 2015
That is just a very generalized list, but you can confirm compatibility by using the information in the following article:
https://eshop.macsales.com/guides/Mac_OS_X_Compatibility
Keep in mind the other Mac can currently be running any version of macOS 10.6+.
If your iMac originally shipped with installation DVDs from the factory, then you also have the option to use an OS X 10.6 Snow Leopard upgrade DVD if is shipped with OSX 10.5 or earlier, or you will need the original gray recovery DVD containing OSX 10.6.x Snow Leopard. After installing OSX 10.6, then you will need to install macOS 10.11 (probably need to use another computer to download the install & transfer to the iMac) followed by upgrading to 10.13.
To install macOS 10.6 to 10.12, you will need to partition & format the whole physical drive (or the Fusion Drive if equipped) using the instructions in the following article since those older versions of macOS do not understand the new drive layout & APFS file system utilized by macOS 10.13 High Sierra.
https://eshop.macsales.com/tech_center/formatting/Mac_Formatting_6-10_R3.pdf
FYI, you should always provide the exact model of the device when asking for assistance online since it is always helpful & many times needed to provide more specific assistance. If you cannot boot the Mac to retrieve this information, then you can enter the system serial number on the check coverage page here:
Check Your Service and Support Coverage - Apple Support