Remove the Source
The most important step to getting rid of a fruit fly infestation is to remove the cause of the infestation. If you keep fruit and vegetables outside of the refrigerator trash them. This is where the fruit flies lay their eggs, which can hatch in as little as a week. Put the fruit and vegetables in a small plastic bag separate from your main garbage and take the bag outside to the garbage can immediately. Keep your produce in the refrigerator from now on.
Make a Trap
The best way to get rid of adult fruit flies is to make a trap. Get a glass jar that has a top. Place a piece of fragrant fruit at the bottom of the jar. Roll a piece of a paper so that it looks like a funnel and place it inside the open jar. Set the trap in a place where the flies like to congregate. The flies will be attracted inside of the jar. Put the top on while they are all inside and throw it out or spray the inside with insect spray to kill them instantly.
Dry Soap
Fruit flies tend to rest and fly around garbage cans, so you will need to repel them from that area and toward your trap. Dry soap (or powdered detergent soap) is an effective fruit fly repellent. Sprinkle a layer of soap powder over the food and trash in the can in your kitchen, even if it is covered (fruit flies can easily get into covered cans). Do this every day for about a week to assure that you are keeping all of the flies out of the garbage and attracting them to your trap instead.