The best way to kill gnats is to wipe them out in their larval stages by allowing wet soil in house plants and other locations to dry completely. Adult gnats around plants or other areas can be removed using the hose attachment of a vacuum cleaner.
For gnats infesting house plants, it is important to repot the plant from time to time with fresh soil. The reason for this is that growing mediums can break down and retain excess moisture and an overabundance of decayed plant matter. This provides a great food source for gnats and helps to support populations indoors.
Finding and eliminating sources of food for gnats can be a vital part of control. For example, fruits exposed to open air are notorious for attracting gnats. Storing fruits in the refrigerator can prolong the ripeness of fruits while protecting them from gnats.
Persistent gnat problems require the use of insecticides. There are treatments available for both larvae and adults. Pyrethroid-based products are generally recommended for use on houseplants, and repeat applications may be necessary.
Nematodes are parasitic insects can be used to control gnats. These microscopic roundworms work by invading gnat larvae and emitting a bacterium that kills off the larvae by ingesting its internal contents.