If you have an external USB drive available the most straight-forward solution is to:
- Make a Time Machine backup of your current 2011 iMac's hard drive.
- Install the new SSD.
- Boot into Internet Recovery Mode and select Restore from Time Machine.
This will actually give you a clean version of your macOS. The Time Machine backup, FYI, is not a traditional bit-for-bit copy/backup of your system. Rather by doing this you will get a fresh copy of macOS installed via the Internet then your "backup" which only contains apps, data, and settings, will be re-integrated into this freshly installed copy.
ALSO: If you are doing this SSD replacement yourself you will really want to get a new thermal sensor that plugs into the power cable since you are replacing the Mac-specific drive with a generic SSD. Otherwise, you're system will run in full-speed fan mode 100% of the time:
https://eshop.macsales.com/item/OWC/DIDIMACHDD11/
So this is the best way for sure, but an alternative way would be to:
- Make a Time Machine backup of your current 2011 iMac's hard drive.
- Install the new SSD.
- Boot into Internet Recovery Mode and select Install macOS.
- This gives you a clean, working install of macOS you can test. Then you could run "Migration Assistant" app to re-integrate the data from your Time Machine backup at that point.
Back up your Mac with Time Machine - Apple Support
How to reinstall macOS from macOS Recovery - Apple Support
How to move your content to a new Mac - Apple Support (if you do the 2nd method)