Use a USB flash drive (or other removable media) as a startup disk from which to install macOS.
macOS is distributed through the App Store which will download an installer app to the /Applications folder.
Links to download older versions [Macworld]
If you run the macOS installer from the /Applications folder, the installer app will be deleted. Therefore your first step after downloading the installer should be to cancel the install. Then copy the installer App somewhere else so that you won't have to download it again.
Installer App names:
Install macOS Catalina.app
Install macOS Mojave.app
Install macOS High Sierra.app
Install OS X El Capitan.app
At the command line, spaces must be escaped so these become:
Install\ macOS\ Catalina.app
Install\ macOS\ Mojave.app
Install\ macOS\ High\ Sierra.app
Install\ OS\ X\ El\ Capitan.app
You need a Mac-formatted drive big enough to hold the installer and its data - 8 GiB.
This can be a hard drive, an SSD, or a USB stick.
The drive must be formatted as a Mac OS Extended (Journaled) volume with a GUID Partition Table.
Name the drive 'Untitled' this name will be changed when the new volume is initialised. The Terminal commands below assume that the drive is named Untitled. You could name the drive to something different as long as you adjust the command line syntax below to match.
The program used to create a bootable drive (createinstallmedia) is supplied as part of the installer App.
Open the terminal and copy one of the following, single line commands. Becasue we are using sudo you will be prompted for a password:
Create a Catalina drive:
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ macOS\ Catalina.app --nointeraction
Create a Mojave drive:
sudo /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ macOS\ Mojave.app --nointeraction
Create a High Sierra drive:
sudo /Applications/Install\ macOS\ High\ High Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ macOS\ High\ Sierra.app --nointeraction
Create a Sierra drive:
sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ macOS\ Sierra.app --nointeraction
Create an El Capitan drive:
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app --nointeraction
If you see the message “To continue we need to erase the disk at /Volumes/Untitled.” Type the letter Y and press Return.
The build process can take 20 minutes or so to complete, wait for the 'Done' message
Erasing Disk: 0%... 10 percent...
Copying boot files...
To boot from an alternate drive restart your Mac while holding down the Option key.
The macOS Startup Manager will then appear and you can select a startup drive.
Related macOS commands:
HT201372 - Create a bootable installer for macOS.
SP803 - macOS Catalina 10.15 - Technical Spec. /requirements.
SP777 - macOS Mojave 10.14 - Technical Spec. /requirements.
SP765 - macOS High Sierra 10.13- Technical Spec. /requirements.
SP742 - macOS Sierra 10.12 - Technical Spec. /requirements.
sw_vers - Print macOS operating system version.