That's a early-to-mid 2009 iMac,
If you install the maximum 8 GBs of RAM, you can either pay to install and run OS X 10.8.5 Mountain Lion OR install tge free OS X 10.11.6 El Capitán which is the highest Mac OS version you can install on that iMac and STILL a fairly recent Mac OS version.
Before embarking on a major OS upgrade, it would be wise, advisable and very prudent if you have a good, working backup of your current system to an external connected and Mac formatted Flash drive OR externally connected USB, Thunderbolt or FireWire 800, Mac formatted hard drive. Then, use either OS X Time Machine app to backup your entire system to the external drive OR purchase, install and use a data cloning app, like CarbonCopyCloner or SuperDuper, to make an exact and bootable copy (clone) of your entire Mac's internal hard drive. This step is really needed in case something goes wrong with the install of the new OS or you simply do not like the new OS, you have a very easy way/procedure to return your Mac to its former working state.
To download and install either the pay OS X 10.8.5 Mountain Lion or the free macOS Sierra OR OS X 10.11.5 El Capitán need one of these Macs:
OS X 10.8 Mountain Lion purchased emailed download code here.
http://store.apple.com/us/product/D6377Z/A/os-x-mountain-lion
Apple will send you an email for the special download code for the Mac App Store, for OS X 10.8.5 Mountain Lion within three days of purchasing the download code.
iMac (Mid-2007 or later)
MacBook (13-inch Aluminum, Late 2008), (13-inch, Early 2009 or later)
MacBook Pro (13-inch, Mid-2009 or later),
MacBook Pro (15-inch or 17-inch, Mid/Late 2007 or later)
MacBook Air (Late 2008 or later)
Mac mini (Early 2009 or later)
Mac Pro (Early 2008 or later)
Xserve (Early 2009)
Your Mac also needs:
OS X Mountain Lion, Lion, or Snow Leopard v10.6.8 already installed
2 GB or more of memory (I strongly advise, at least, 4 GBs of RAM or more)
8 GB or more of available space
Next,
you run any older Mac software from the earlier PowerPC Macs, then none of this software will work with the newer OS X versions (10.7 and onward). OS X Snow Leopard had a magical and invisible PowerPC emulation application, called Rosetta, that worked seamlessly in the background that still allowed older PowerPC coded software to still operate in a Intel CPU Mac.
The use of Rosetta ended with OS X Snow Leopard as the Rosetta application was licensed to Apple, from a software company called Transitive, which got bought out, I believe, by IBM and Appe could no longer secure their rights to continue to use Rosetta in later versions of OS X.
So, you would need to check to see if you have software on your Mac that maybe older than, say, 2006 or older.
Also, check for app compatibilty here.
http://roaringapps.com/
If you have any commercial antivirus installed and/or hard drive cleaning apps installed on your Mac, like MacKeeper, CleanMyMac, TuneUpMyMac, MacCleanse, etc. now would be a good time to completely uninstall these apps by doing a Google search to learn how to properly uninstall these types of apps.
These types of apps will only cause your Mac issues later after the install of the new OS X version and you will have to completely uninstall these types of apps later.
Once you have determined all of this, you should be able to find the latest versions of OS X by clicking on the Mac App Store icon in the OS X Dock and then login to the Mac App Store using your Apple ID and password and if you purchased a download code, input that code.
You can then begin the download and installation process of installing the newer versions of OS X from the Mac App Store.
You MUST use THE EXACT RAM that your model iMac is spec'd for.
Proper spec’d and reliable Mac RAM can ONLY be purchased from online Mac RAM sources Crucial memory (crucial .com) or OWC, aka, Other World Computing (macsales.com).
When buying RAM for Macs from Crucial memory, purchase ONLY directly from the Crucial memory website. NOT from some other online source.
https://eshop.macsales.com/shop/memory/iMac/DDR3_2009
RAM modules are, relatively, easy to install.
https://eshop.macsales.com/installvideos/imac_mid_2007_mem/
Good Luck to You!