There are many species of ants -- some more benign than others. Ants become a garden pest when they spread aphids to your plants or, in the case of fire ants and carpenter ants, feed on your fruits, vegetables and flowers. Though you will never eliminate outdoor ants completely, there are several ways to deal with them when you must. These methods range from deterring the ants to killing then. Ants do serve a purpose and can be beneficial, so killing them should be considered only when deterrents don't work or when the infestation is severe.
Crushed red pepper flakes and chili pepper sometimes work as an ant deterrent. Sprinkle these spices around the plants you want to protect and around any anthills you find. Alternatively, you can try combining water and hot sauce and spraying it on your plants to deter the ants. Wash any edible plants before you eat them.
Spraying plants with insecticidal soap will kill insects and is safe to use on edible garden plants. To spray your plants, combine 2 tablespoons of insecticidal soap and 1 quart of water in a spray bottle for easy application. If you find ants in potted plants, soak soak the soil in the pots for 20 minutes using the same insecticidal soap and water mixture, making sure the water is high enough to just cover the top of the soil.
Ants like the sweet nectar produced by aphids and sometimes herd and protect them so they have access to more of it. One way to get rid of ants in your garden is to get rid of the aphids. Aphids can generally be removed with a blast of water from the garden hose but severe infestations may require treatment with an insecticidal soap.
If ants are bothering one or two plants in particular, protect the plants with a sticky barrier that will stop the ants from climbing up the trunk or stem and reaching the foliage. When using this method, be sure to wrap the trunk or main stem of the plant with fabric tree wrap tape to protect it. Apply the sticky barrier to the tape and be sure to change it as needed to keep the sticky barrier fresh and prevent girdling the plant as it grows.
Ants collect the bait as a food source and take some of the bait back to the colony, helping to wipe it out and potentially killing the queen. While you certainly can't control the entire outdoor ant population, you can use baits in your garden to try and kill the specific ant colonies that are eating your plants. Try several different bait stations in the garden as different ant species have different tastes; some prefer sweet baits while other prefer protein-based baits.
Made by crushing fossils of algae and available in hardware stores and garden centers, diatomaceous earth injures and kills ants and other insects that walk across it. This helps with slugs and other garden pests as well as ants but could harm beneficial insects, including those that prey on ants, so use it only as a last resort. Diatomaceous earth is safe to use around edible plants but harvested fruits and vegetables should be washed before use to prevent ingestion of the diatomaceous earth particles. This ant control will need to be reapplied after rain or watering as it becomes ineffective when wet.