The answer to 'how to get rid of centipedes' is to use a combination of prevention and targeted treatment. Centipedes are common household pests that can be difficult to eliminate, but there are several effective methods to get them under control.
First, focus on prevention by sealing cracks and crevices around your home where centipedes may enter. Use caulk or weather-stripping to close up any openings. Reduce moisture by fixing leaks, improving ventilation, and using a dehumidifier if needed. Eliminate clutter and organic debris where centipedes can hide and breed. You can also use diatomaceous earth, a natural mineral dust that damages the exoskeleton of insects like centipedes.
For active infestations, you can try targeted treatments like insecticide sprays or baits. Look for products containing pyrethrin or other insecticides labeled for centipede control. Apply them in areas where you've seen centipedes, following the product instructions carefully. If the infestation persists or you have a severe problem, it's best to call in a professional pest control technician who can properly identify the issue and implement more comprehensive treatments.