Trap the flies in a jar: First place a small piece of ripe fruit or a few drops liquor or beer in an open jar, and then place a paper funnel (such as a coffee filter with the tip snipped off) in the top. The fruit flies will fly in and become trapped. You can kill them by pouring in boiling water.
Another option is to set out a shallow dish of apple-cider vinegar. Cover the bowl in plastic wrap; using a needle, punch a half dozen holes in the surface at least a half inch in from the edge of the bowl. As with the paper-funnel method, the fruit flies will fly in and get trapped.
Keep a few sprigs of fresh basil in a bowl or a potted basil plant near fruit and vegetables. Many cooks use this time-honored method with good results; some even find that setting a pot or two of basil outside the kitchen door keeps flies from entering the room.