The answer to 'how to prevent centipedes' is to take steps to eliminate their food sources and make your home less inviting for them. Centipedes are attracted to damp, dark areas and feed on other insects, so keeping your home clean and dry is key.
Start by sealing any cracks and crevices around your home where centipedes could enter. Use caulk or weatherstripping to close up gaps around windows, doors, pipes, and electrical outlets. Dehumidify damp areas like the basement, crawl space, or bathroom. Fix any leaks and improve ventilation to reduce moisture. Regularly vacuum, sweep, and remove clutter to eliminate hiding spots and food sources for centipedes and other pests.