My iMac is 7 years old and was getting slow and glitchy
I asked an ifixit staff to guide me to the right hardware because you can't just throw any old HD in a mac. For barely more than $200 I went from a slow 1TB 8g computer to a perfect 4TB 12g computer!!! It was pretty seamless! Everything you need for understanding of the process is found online, and most of it on the ifixit site.
Make sure to:
1. make a time machine backup
2. make a bootable USB for the OS - google this process
3. after the hardware install, format the new drive - enter disk utility on startup
4. install OS - choose after exiting disk utility
5. import old files