On a compact spin manifold we study the space of Riemannian metrics for which the Dirac operator is invertible. The first main result is a surgery theorem stating that such a metric can be extended over the trace of a surgery of codimension at least three. We then prove that if non-empty the space of metrics with invertible Dirac operators is disconnected in dimensions $n \equiv 0,1,3,7 \mod 8$, $n \geq 5$. As a corollary follows results on the existence of metrics with harmonic spinors by Hitchin and B\"ar. Finally we use computations of the eta invariant by Botvinnik and Gilkey to find metrics with harmonic spinors on simply connected manifolds with a cyclic group action. In particular this applies to spheres of all dimensions $n \geq 5$.