Rats like living in houses because houses provide shelter, a refuge from predators and often a plentiful supply of food. Keeping rats away involves making your house seems as little like a rat hotel as possible and, if necessary, using repellents and physical barriers to keep the rodents away.
The number one way to keep rats away is removing all sources of food. Keep pantry goods in glass or ceramic containers; vacuum all crumbs from floors, behind furniture and under appliances; and put leftovers away immediately. Don't leave dirty dishes lying about. Rats are omnivores and will eat practically anything, including fruit, pet food and birdseed. If you have pets, don't leave their food out, either. If you have small pets in cages, give them spill-proof feeders so they don't kick food out. Keep garbage in tightly sealed cans both inside and outside.
Food might be the primary attractant to rats, but they also need water. Fix leaking pipes, and wipe condensation off windows and from around fridges daily.
Rats are scared of potential predators, a group that includes humans. The fact that there are people living in the house may be enough to deter more timid rat populations, if there is no food to attract them. Letting your cat or dog have the run of every room also helps. If you don't have a pet, borrowing a friend's dog and walking it through the house occasionally leaves the scent of a predator behind. Large-cat urine or dung is available from garden supply stores or local zoos, and worth trying, especially in little-used rooms such as attics. This isn't as malodorous a solution — to you — as it might appear, and gives rats one more reason to leave your house alone. If you have a yard, encouraging natural predators such as owls and snakes keeps local rodent populations under control. Overpopulation can drive rodents inside. Snakes need dense shrubbery and a loose stack of scrap wood. Keep use of outside lights at night to a minimum to encourage owls.
Sonic rodent repellents may or may not work. Such products get mixed reviews, and some people swear they work. There isn't much scientific evidence to support this, but there is no harm trying them. Sonic devices might not deter established rats, but may be enough to deter rodents that are deciding whether to move into your home or the one next door. Other repellents include peppermint oil, which works well on mice but not always on rats, ammonia and a whole range of commercial preparations.
Sealing all potential rat entrances is quite a big job, especially in a large or old house. To do this, you need the appropriate building materials and a flashlight. Locate and seal all gaps a rat could squeeze through. Remember, if a rat's head can fit through a hole, the rest of the body can follow. This means a gap less than an inch wide is a potential rat door. Pay particular attention to plumbing fixtures, skirting boards and windows.