In order for you to upgrade to Mojave with a clean installation of macOS, You need to create a bootable macOS Mojave USB drive. You can then use an External drive or the secondary volume (USB) to install the macOS using it as a startup disk.
The command-line installation of macOS would come as savvy mainly for the system administrators. You really do not require a bootable installer to upgrade macOS or reinstalling the operating system, It only will be useful when you have multiple computers lying around and you need to download and use the installer each time.
You must also require a USB 3.0 Drive with at least 16 GB of storage and please ensure you have taken a backup of all the files in your USB 3.0 flash drive as this installation will erase and remove all the files from your flash drive.
You can get USB 3.0 from Here
You can download macOS Mojave From Here
if you have downloaded already macOS Mojave directly, then the downloaded macOS itself to the applications folder as an individual app called “Install macOS Mojave”. Sometimes it is also possible that the installer opens itself right after downloading it, You need to ensure quitting it without proceeding to go with the installation directly. Also, it is important for you to download the correct version of macOS as per your mac.
How to create a bootable installer for macOS Mojave
Step 1: Download macOS Mojave.
Step 2: Once Mojave is downloaded, You should make sure that you close the installer and Open the finder.
Step 3: In Finder, You need to head over to Application → Install macOS Mojave right click on install macOS Mojave and click Show package contents.
If You have downloaded from the link then go to Download → macOS Mojave.
Step 4: Head over to open Content → Resources
Step 5: Using Finder another window and Go to Applications and Select Utilities → Terminal
Step 6: Type sudo followed by space
Step 7: Now from the original finder window opened in step 4, drag and drop the createinstallmedia to terminal
Step 8: Type —volume along with space
Step 9: Open Finder and click Go at the top followed by Go to folder menu or by pressing command + shift + g at the same time.
Step 10: Type /Volumes and click go to navigate to the volumes that is connected to your mac
Step 11. You should probably find your connected USB 3.0 Flash drive on your Mac in the Finder window
Step 12: Now Drag the USB 3.0 Flash drive volume to the Terminal window
Step 13: Now press Enter / Return on keyboard
Step 14: Type y so you can continue the progress and Press Enter / Return on the keyboard again.
After the above process, You can also use the USB 3.0 drive to boot into macOS Mojave installer Once you connect your USB 3.0 flash drive, Then restart your Mac by pressing the Option (⌥) button modestly. Then you may select the macOS Mojave Installer to get started with the installation.