Press power on button and hold it in for about 6 seconds until Mac shuts off.
Now press power on button again and immediately hold down "command-option-R" until the "internet symbol" appears.
If you are not connected via ethernet, you may have to enter your wifi password.
See if you can get to the Mac Utilities screen (may take a little while for everything to "come in" over the net and get loaded and ready).
(You didn't tell us WHICH version of the Mac OS you want to install?)
I would then open Disk Utility and ERASE the internal drive (if it's High Sierra or Mojave, go to the popup menu on the left and choose "show all devices").
I would choose "Mac OS extended with journaling enabled".
Then open the OS installer and try again.