It depends where they live. Is it in your garden or are they moving into your house? The 2 main reasons why they move into your house is because of lack of food, or unsuitable conditions outside.
First, make sure there is no food in your house to attract them to come. Without food, they have no major motivation to enter your home. You can use an aerosol spray, but a better option is to use an ant trap.