To avoid infestation by ants, follow clean and hygienic practices. Be careful while handling food. Do not drop food crumbs in the floor or your bedding, and leave it uncleaned.
Eat at a particular place, say the kitchen or dining table. Do not move around with the food plate in your hand. If you notice that you dropped food, clean it as soon as you finish eating. Wipe the place with a wet cloth.
Handle sweets carefully. Do not drop it on the floor. Clean the counter or plates where the sweets had been kept. Store sweets in an airtight container. You can also keep it in the fridge if the desert is such that it can be kept inside. Avoid keeping sweets and munching items out in the open.
Seal gaps in the windowsill, cracks on the walls, gap between the door and the walls etc. Sweep the house everyday and wipe it with wet cloth. You can use a good detergent or liquid solution to clean the floor, the kitchen counter and the sink. Using boric powder also helps in preventing ants.
Discard unwanted wrappers, covers, and stale/decaying food items from the house. Keep the garbage bin dry and clean. Keep the bin outside the house and empty the contents at a far off place. Use disposable plastic/paper bags so that the garbage bin can be carried easily and the bin also does not get soiled.
If you have indoor plants, discard fallen leaves, petals and other trash so that ants do not get a secure place to stay. Use an insecticide if you see infestation by pests or insects.
To get rid of ants, you can also sprinkle powder of black pepper, cinnamon, cloves or bay leaves at the probable places from where the ants can enter. The ants will not invade the space due to strong odour emitted by these substances.