Published April 04, 2022

Apple normally allows you to download full copies of their operatings systems from the App Store. They also give you the option to download updates directly from Apple Support. Apple also has a hidden feature that allows you to download the full macOS installers (for the supported versions listed below) directly from the command line. Be sure to replace the x with the latest release number. After the download finishes, you will see the installer appear in the "/Applications" directory.
Latest Release
As of the publishing date of this article, the latest release is macOS 12.3.1. You can download that with the following command.
softwareupdate --fetch-full-installer --full-installer-version 12.3.1
Previous Releases
macOS 12 Monterey
softwareupdate --fetch-full-installer --full-installer-version 12.x
macOS 11 Big Sur
softwareupdate --fetch-full-installer --full-installer-version 11.x
macOS 10.15 Catalina
softwareupdate --fetch-full-installer --full-installer-version 10.15.x
macOS 10.14 Mojave
softwareupdate --fetch-full-installer --full-installer-version 10.14.x
macOS 10.13 High Sierra
softwareupdate --fetch-full-installer --full-installer-version 10.13.x
Older operating system versions
Some of the older versions are available for download from the terminal using the command below. These commands should run on all versions of macOS.
macOS 10.12 Sierra
curl -O http://updates-http.cdn-apple.com/2019/cert/061-39476-20191023-48f365f4-0015-4c41-9f44-39d3d2aca067/InstallOS.dmg
OS X 10.11 El Capitan
curl -O http://updates-http.cdn-apple.com/2019/cert/061-41424-20191024-218af9ec-cf50-4516-9011-228c78eda3d2/InstallMacOSX.dmg