There’s little that makes you feel better than gardening with your own sustainably created compost. You’re not only fertilizing your plants—you’re also finding a way to recycle food waste. But the compost heap quickly becomes a source of stress and aggravation instead of pride and practicality when fruit flies make it their home. Whether you keep your compost pile indoors or out, fruit flies are an unsightly and annoying addition.
First of all, you should know that these fruit flies are harmless visitors. They won’t damage the compost itself, and fruit flies do not bite; they lack the equipment to do so (mouth or teeth). However, once they’ve been attracted by fermenting produce, an infestation can bring a swarm of thousands of these tiny insects into your home or garden. It’s best to handle them quickly, though, before they can multiply and start looking for other sources of food—like your fruit bowl on the counter or tomatoes growing on the vine.
Increase Your Ratio of Brown to Green Compost Material
The go-to solution for many gardeners when facing a flurry of fruit flies is to add more brown material to balance the compost. Because the bugs are attracted to decomposing fruit and vegetables, the “browns” help the material in your compost to dry out, discouraging the swarm. (Remember that “browns” in compost include leaves, twigs, sawdust, dried plant material such as hay, unprinted paper, fabrics, unwaxed cardboard, or dryer lint. Your compost pile should be 50-80 percent brown material, though exact proportions vary based on who’s doing the recommending.)
Because the insects aren’t too keen on feeding on these brown materials, you can use them to seal off your compost, and they’ll look for a meal elsewhere. Make sure the top layer of your compost is browns to discourage the flies.
Buy or Build a Fruit Fly Trap
If you know your compost is balanced between brown and green, consider going on the offensive and trapping the bothersome insects. You can purchase fruit fly traps at home supply stores such as Home Depot, at major grocers, or online. There are also several homespun methods for trapping these little buggers. One of the solutions below should work for you.
Apartment Therapy: Cider vinegar, dish soap, jar, and plastic wrap 
Taste of Home: Five methods to choose from
Handle Scraps Carefully
There are a few precautions you can take with scraps you’re adding to your compost to help make it less hospitable to fruit flies. Try a few to find out whether one of these solutions will be both convenient and effective in your case.
Because your kitchen scraps are what’s attracting the flies, making them less accessible in the pile will help keep your compost pest-free. You can wrap scraps in butcher paper and add them to your pile in bundles. Boiling the foodstuff before adding it to your compost is another way to make it less attractive for fruit flies.
Consider the Source
It may be the case that the container you’re using for compost is part of your problem. Intuitively, you’d expect that a lidded compost container would be optimal for keeping fruit flies out. Some gardeners say this isn’t the case, though. You may need to adjust your setup to determine which method is best for you—lid or no lid.
For some people, a lidded container actually does prevent the flies. But whether it’s because the flies are trapped inside by the lid or they prefer the darker environment inside, some people report going lidless put a stop to their infestations. Of course, this tip is only practical if you don’t have to worry about raccoons or other critters that may get into an exposed compost pile.
Some gardeners use an outdoor pile with an indoor bucket to hold scraps until a full load is ready. If this is your preferred method and you’re dealing with fruit flies inside, the solution may be simple. For a few days (or until the invasion has ended), don’t use that indoor holding area. Instead, take compost directly outdoors so the fruit flies in your home will be forced to hit the road to find food.
Go On the Offensive
If none of these tips work for your situation and you’re at your wit’s end, there’s one last tip to try. Some people report that boiling a pot of water (or as many pots as you need) and splashing it thoroughly on the compost heap will kill any flies making it their home as well as their eggs.
If you use a lid, shut it immediately after this step to trap the heat inside and steam the offending insects. Splash some of the hot water on the outside of your bin (both top and sides), too. Diatomaceous earth is another weapon against fruit flies, and you can add it right to the compost without fear of harming it.
While a fruit fly scourge can certainly be irritating, it isn’t a major problem for your compost pile outdoors, and they can easily be ignored outside.
It really only becomes a problem when you bring them indoors and they start to fly around any fruits or kitchen scrap collectors you have inside to collect your scraps before you throw them into the outdoor bin.
You shouldn’t lose any of your compost by following these tips, so you’ll still have access to the fertilizer that results from your work. Have you found success with a method we haven’t covered? Leave us a comment to let us know what’s worked for you.
Erin Marissa Russell graduated TWU in 2013 with honors, majoring in English and minoring in intermedia art. In May of 2017, she opened Russell Gibson Content to expand her freelance career into a talent agency for writers and editors, which is now a full-time operation with 60 contractors. With her husband Matt Gibson, she researches speleofolklore, a term the two coined to describe the study of legends surrounding caves, with particular attention so far to the caves of Texas. They are working on a novel based on a legend from Cascade Caverns in Boerne, Texas, and regularly present their work at Texas Folklore Society conferences and other meetings.
Learn More about Avoiding Fruit Flies