You can use macOS Recovery to manually upgrade your computer to the latest compatible macOS version. This method requires an internet connection during the upgrade process and is only for major macOS releases.
To install the latest macOS version compatible with your computer, start up from macOS Recovery by turning on your computer and pressing Option-Command-R. If you want to erase the data on the computer before installing macOS, you can use the Disk Utility.
For more information on how to install macOS from macOS Recovery, see the following article from Apple's support website: https://support.apple.com/HT204904