Create a bootable installer for macOS
See the source article at support.apple.com
With macOS High Sierra, Sierra, El Capitan, Yosemite, or Mavericks, you can use a USB flash drive or other storage media as a startup disk from which to install the Mac operating system.
You don't need a bootable installer to reinstall macOS, but it can be useful when you want to install macOS on multiple computers. These are advanced steps, intended primarily for system administrators and others who are familiar with the command line.
Download the macOS installer from the App Store
Download the macOS installer from the Mac App Store. The installer downloads to your Applications folder as a single file with a name that begins ”Install”. For example: Install macOS High Sierra.
If the installer opens automatically after downloading, quit the installer.
Mount the USB flash drive, external hard drive, secondary internal partition, or other storage media that will contain the install media. Make sure that it has at least 12GB of available storage space.
Continue to the next section.
Use the 'createinstallmedia' command in Terminal
After downloading the installer, open the Terminal app, which is in the Utilities folder of your Applications folder.
Use the createinstallmedia command in Terminal to create the bootable installer. This is the basic syntax of the command:
Syntax for High Sierra:
createinstallmedia --volume volumepath
Syntax for Sierra and earlier:
createinstallmedia --volume volumepath --applicationpath installerpath
Replace volumepath with the path to your USB flash drive or other volume. Replace installerpath with the path to the installer.
The following examples assume that the installer is in your Applications folder, and the name of your USB flash drive or other volume is MyVolume:
Example for High Sierra:
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume
Example for Sierra:
sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ macOS\ Sierra.app
Example for El Capitan:
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app
Example for Yosemite:
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ Yosemite.app
Example for Mavericks:
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ Mavericks.app
For more information about the createinstallmedia command, make sure that the macOS installer is in your Applications folder, then enter the appropriate path in Terminal:
Path for High Sierra:
/Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia
Path for Sierra:
/Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia
Path for El Capitan:
/Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia
Path for Yosemite:
/Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia
Path for Mavericks:
/Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia