How to fix Mac “file system or verified failed”? Mac gets stuck when trying to update and I get the error “macOS could not be installed on your computer, file system verify or repair failed”.

I tried using disk utility and running first aid. I get the following error: 
the volume Macintosh hd could not be verified completely.
File system check exit code is 8. 
File system or repair failed. 
Operation failed. 

What do I need to do here to get my computer running again. I have transferred all files I need onto another computer. 

Thanks
So it sounds like you have a disk error of some sort that Disk utility can't fix. This does happen from time to time and is the reason things like Diskwarrior exist.

Assuming you don't have access to a third-party disk repair tool (Diskwarrior, etc.) and you do not have High Sierra (disk repair tools don't work on APFS disks yet) then you can reformat your MacHD volume and reinstall from scratch.

If at all possible it could be a bit faster to create a macOS install thumb drive so you don't have to wait on Recovery Mode to download the OS as it installs.

If you do it that way, boot from the thumb drive and once you get to the install screen you should have a menu option to launch Disk Utility. Do so, select the MacHD volume (or whatever it is called) and format it. Once that is done you can proceed with installing macOS and restoring your files and Apps.

If you are doing it from recovery Mode. Launch Disk utility first and (as above) format the MacHD volume before proceeding with the OS install.

Formatting a volume (assuming it is not a hard (or physical) error) will usually wipe out most common volume corruption/damage errors, making it OK to reinstall whatever was on it to begin with.

If it turns out it is a physical error of some sort then after formatting the volume you will either get an error that it could not be formatted or running disk repair on it will still return errors. In that case it is likely that the spinning disk or SSD needs to be replaced.