Generic bug sprays, as well as DEET, are common sprays used to keep gnats away. However, there are less harmful alternatives available for those not wishing to use harsh chemicals.
Citronella plants and vanilla act as natural gnat deterrents. Gnats can also be trapped using vinegar and dish soap in places where sprays cannot be used, such as around food. To make a simple gnat trap, pour vinegar into a cup or dish and add a few drops of dish detergent. Cover the container with plastic wrap and secure it with a rubber band before using a toothpick to gently poke holes in it. The vinegar attracts the flies and the combination of the soap and the plastic wrap traps them in.