The answer, unfortunately, is to ensure you have as much hard drive storage as you can. If you have a PS4 with the standard 500GB hard drive, you'll probably find it fills up pretty quickly. In order to download and install new games, you will probably have to delete some older titles. Remove the game data for some games you don't play anymore to keep your hard drive as clutter free as possible.
Of course, you can also expand PS4's storage space. You can install bigger hard drives and even SSDs into your PS4, or you can simply plug a USB external hard drive into one of your PS4's USB slots. Pretty large external hard drives can be bought nowadays fairly cheaply, and having more space than you need will ensure you don't get this annoying issue with your PS4 anymore.