Mildew, overripe or spoiled produce, organic garbage and compost can attract gnats. Use tightly covered bins to store your trash and compost, and store fruits and vegetables in the refrigerator instead of on countertops and tables. Scrub away mildew on bathroom tiles with a commercial cleanser or white vinegar solution, and pour boiling water down sink drains to eliminate buildup.
Overwatering is one of the leading causes of poor plant health and death. Larvae thrive in damp soil, and excess moisture at the soil's surface attracts adult flies. Wait for soil to dry out thoroughly before watering your plants -- larvae will die in drenched soil, and adult flies will not lay eggs in it.
The color yellow attracts gnats. Place yellow sticky cards on the surface of soil to trap flies, and dispose of the cards as you wish. Fly traps hung from the ceiling will also trap gnats.
The smell of fermenting liquid attracts certain gnat varieties as well as fruit flies, which are often mistaken for gnats. Pour 2 inches of apple cider vinegar or beer into open containers and add a drop of liquid dish detergent. Place the traps wherever gnats are a problem to attract and drown them.
Spray insecticidal soap on houseplants, including the undersides of leaves, to eliminate gnats. Insecticidal soap is an organic product available from garden suppliers. Test a small amount of soap on plants before administering a full application.
Commercial insecticides containing pyrethrum can effectively reduce gnat populations with repeated applications. Before applying a chemical insecticide, close windows and doors, store exposed food products and remove children and pets from the premises. Spray a mist of insecticide in the air and leave the room for at least an hour to prevent inhalation of harmful chemicals. Chemical insecticides should be used as a last resort when natural methods are ineffective.