Remove Water Sources
Allow the top 2 inches of soil to dry between each watering. Removing the water source will prevent the eggs laid in the soil from hatching. When the gnats do not have a water source, they will not be as attracted to the medium. Remove any freestanding water, such as water left in the bottom of a growing container saucer. Transplant the plant into a container with adequate drainage holes. If the soil cannot drain, then the soil will remain damp and attractive to the gnats.
Remove Organic Material
Remove decomposing and moist organic materials from the yard because gnats feed on these materials. Areas with compost, grass clippings, mulch and fertilizers are where the gnats will also breed. Remove these materials and place them in a lawn bag or trashcan. If you are creating compost in your yard or placing it in the garden, always make sure it does not remain too moist and that it decomposes properly.
Vinegar and Dish Soap
Combine 1/2 quart of water with 2 tbsp. of apple cider vinegar and 2 tbsp. of sugar to attract the gnats. Add two to three drops of liquid dish soap to the vinegar. You can also combine an equal amount of apple cider vinegar with cheap beer. Place the solution in the areas where you notice the gnats. The solution will attract the gnats and repel them away from the plants. The gnats will try to drink the vinegar, but the soap will trap the gnats in the solution. Replace the solution when it becomes full of gnats. Continue to use the trap until you've controlled the gnats effectively.
Use pasteurized soil if the organic matter has not completely composted, as it may contain fungus gnats. Remove excess organic debris from crops and buildings to prevent feeding the gnat larva. Close doors and windows in buildings to prevent the gnats from invading indoor plants. Turn off outdoor lights and porch lights when you are not using them --- gnats are attracted to them. Place strong essential oils such as mint, lemongrass, citronella or garlic around gnat-infested areas.