Fruit flies were a nuisance to me my freshman year of college. They would come out of nowhere and attack the ripe fruit on my desk. They would even hover above my compost bin that was filled with fruit pits and banana peels. My only solution to getting rid of them would be to eat all of my fruit quickly and empty my compost bin frequently.

Other methods of getting rid of fruit flies usually involve using certain products like vinegar and fly traps. However, it's easier to take some of the proceeding steps to prevent fruit flies from showing up at all.

Washing the Fruit

banana, juice, pasture, vegetable, apple, pineapple
Jocelyn Hsu

Sometimes fruit flies attack your fruit before you even buy it. In the store, fruit flies can lay their eggs on the fruit. So once you buy your fruit, wash it to remove any potential fruit fly eggs. 

Disposing of Rotten Fruit

Rotten Apples

cogdogblog on Flickr

Fruit flies like to make an appearance when rotten fruit is present. Because of this, check the entire surface of fruit to look for rotten parts and slightly squeeze it to see if it's rotting from the inside. Then, compost any rotten fruit.  

Keeping Countertops Clean

Kitchen

Jeremy Levine Design on Flickr

Fruit flies are known to love fruit, hence their name, but they consume practically any type of sugary food. Cleaning your countertops will remove food like spilled drinks and crumbs from the mouths of fruit flies. 

Closing Windows

Kitchen Window

hzeller on Flickr

Like any other insect, fruit flies enter a kitchen through doors and windows. Unfortunately, you can't keep your door closed forever unless you submit to never leaving again. However, windows can be easily closed. Closed windows prevent easy access for fruit flies. 

Having a clean environment is key in preventing fruit flies. The steps mentioned above are fairly simple. Following them should stop those annoying flies from ever appearing.