We combine a semi-analytic model of galaxy evolution with constraints on circumstellar habitable zones and the distribution of terrestrial planets in order to probe the suitability of galaxies of different mass and type to host habitable planets, and how it evolves with time. We find that the fraction of stars with terrestrial planets in their habitable zone (known as habitability) depends only weakly on galaxy mass, with a maximum around 4 × 1010M⊙. We estimate that 0.7% of all stars in Milky Way-type galaxies to host a terrestrial planet within their habitable zone, consistent with the value derived from Kepler observations. On the other hand, the habitability of passive galaxies is slightly but systematically higher, unless we assume an unrealistically high sensitivity of planets to supernovae. We find that the overall habitability of galaxies has not changed significantly in the last ∼8 Gyr, with most of the habitable planets in local disk galaxies having formed ∼1.5 Gyr before our own solar system. Finally, we expect that ∼1.4 ×109 planets similar to present-day Earth have existed so far in our galaxy.