How to Get Rid of Fruit Flies
Remove the breeding source first.
Look for overripe produce, spills, and residues in recycling.

Step by step
Find where they gather
Check fruit bowls, potatoes or onions stored out of sight, recyclables and wet mops. Small flies near a drain can also be a different species, so look for the most active area.
Clean and store food
Discard spoiled produce, refrigerate ripe fruit where appropriate, rinse containers, and wipe residue. Empty waste bins and keep surfaces dry.
Use a trap for lingering adults
A small trap can catch adults while the source is addressed. If new flies keep appearing, return to the search for a breeding site before adding more traps.
Official instructions and references · University of Kentucky Entomology