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. If you run the macOS installer from that default location, the installer app will be deleted. Therefore your first step after downloading the installer should be to cancel the actual install. You can then copy the installer App and you may also want to back it up so that you won't have to download it again.
Installer App names:
Install macOS Sierra.app
Install OS X El Capitan.app
Install OS X Yosemite.app
Install OS X Mavericks.appAt the command line, spaces must be escaped so these become:
Install\ macOS\ Sierra.app
Install\ OS\ X\ El\ Capitan.app
Install\ OS\ X\ Yosemite.app
Install\ OS\ X\ Mavericks.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 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
Create a Yosemite drive:
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction
Create a Mavericks drive:
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.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...
Copy complete.
Done.
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.
KB-sp742 - MacOS Sierra - Technical Spec. /requirements.
KB-sp728 - OS X El Capitan - Technical Spec. /
requirements.
KB-sp711 - OS X Yosemite - Technical Spec. /requirements.