Not to be confused with fruit flies, the pesky gnat loves moisture. This attack is three-pronged: first the adults, then the larvae, then the breeding sites.
Getting rid of the gnats is the easy part. They love beer! They love cider! Just put a little bit in a shallow dish and leave over night. Just like a moth to a flame, the gnat will find your dish and drown in it. You will probably find several bodies floating in there in the morning.
Step2
Getting rid of the larvae is more difficult. They love moisture. If you have any potted plants in or around your house this is probably where your gnats first appear. Slice a potato and put it, moist side down, on the soil near the plant roots. In the morning you will find several larvae attached to the potato. Flush it away! Be sure your plant soil is dry to make this really effective.
Step3
Find and eliminate all sources of fungus, mold, moisture, algae and etc. This could be the underside of wooden benches, the drippy part under your sink, the old wood pile alongside your house... this is where the gnats will go again and again no matter what you do.
Tips & Warnings
Finding and eliminating the breeding areas is the hard part. Don't give up!
Gnats specially love rotting wood, including old leaves and compost.
Rotenone and Pyrethrum insecticide sprays are also sometimes effective. Though they may damage your plant with repeated use. I urge you to go organic whenever possible. Mother Nature will thank you for it!