Safari is upgraded when you upgrade macOS.
What macOS are you currently running and what model year is your iMac?
The model year of an iMac is available at Apple menu > About This Mac.
An early 2009 iMac can be upgraded to El Capitan 10.11.6 but no later version
A late 2009 through mid 2011 iMac can be upgraded to High Sierra 10.13.6 but no later version.
A late 2012 through late 2013 iMac can be upgraded to Catalina 10.15.7 but no later.
A mid 2014 and late 2014 iMac can be upgraded to the latest version of Big Sur macOS 11 but no later.
A late 2015 iMac can be upgraded to the latest version of Monterey macOS 12 but no later.
A 2017 iMac can be upgraded to the latest version of Ventura macOS 13 but no later.
For all of the above, see instructions in: How to download and install macOS - Apple Support
A 2019 or later iMac can be upgraded to the current version of Sonoma macOS 14. See:How to upgrade to macOS Sonoma - Apple Support
If you can’t or don’t want to upgrade, you may want to use a 3rd party internet browser that supports running their current version on your Mac.