How do I prevent my MacBook from sleeping when downloading apps from the App Store
If you don't want to install any software or change settings, you can use the Terminal utility caffeinate. Open Terminal (located in /Applications/Utilities/), type in caffeinate, and press return ↩︎.

If you want to set a timeout so it will go to sleep after some amount of time, use this:

caffeinate -t 3600


That will make it stay awake for an hour. (3600 is the number of seconds you want it to stay awake.)

To stop or cancel the caffeinate command, press ^ ControlC.