The answer to 'how to prevent centipedes' is to take a proactive approach to pest control and make your home less appealing to these pests. Centipedes are attracted to damp, dark environments, so focus on reducing moisture and eliminating hiding spots around your home.
Start by sealing any cracks and crevices where centipedes may enter, using caulk or weatherstripping. Make sure to repair any leaks or water damage, and use a dehumidifier to keep humidity levels low. Trim back vegetation around the exterior of your home, and remove any piles of wood, leaves, or other organic debris that could provide shelter for centipedes.