There is no way to prevent earthquakes from happening. Since they are caused by the movements of plates that make up the Earth's crust, they cannot be prevented by any means that human beings now have available to them.
What we can do is to try to make earthquakes less damaging. Countries that get a lot of earthquakes and are relatively rich have building codes that require buildings to be made in ways that allow them to survive earthquakes. The main way of doing this is to require that the buildings be made so that they can flex and twist in earthquakes. Buildings that are stiff, no matter how strong, are much more likely to break when stressed by an earthquake.