With macOS Sierra, El Capitan, Yosemite, or Mavericks, you can use a USB flash drive or other removable media as a startup disk from which to install the Mac operating system.

First of all, you need to download OS installer app from AppStore. Just search for name of OS in AppStore and there will be no difficulties with finding it.

Then open Terminal app and follow the instructions below.

This is the basic syntax of the command. Replace volumepath with the path to your USB flash drive or other volume, and replace installerpath with the path to the Install OS X app.

createinstallmedia --volume volumepath --applicationpath installerpath

The following examples assume that the OS X installer is in your Applications folder and the name of your USB flash drive or other volume is 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