The use of radiofrequency linacs for hadrontherapy was proposed about 20 years ago, but only recently has it been understood that the high repetition rate together with the possibility of very rapid energy variations offers an optimal solution to the present challenge of hadrontherapy: "paint" a moving tumor target in three dimensions with a pencil beam. Moreover, the fact that the energy, and thus the particle range, can be electronically adjusted implies that no absorber-based energy selection system is needed, which, in the case of cyclotron-based centers, is the cause of material activation. On the other side, a linac consumes less power than a synchrotron. The first part of this article describes the main advantages of high frequency linacs in hadrontherapy, the early design studies, and the construction and test of the first high-gradient prototype which accelerated protons. The second part illustrates some technical issues relevant to the design of copper standing wave accelerators, the present developments, and two designs of linac-based proton and carbon ion facilities. Superconductive linacs are not discussed, since nanoampere currents are sufficient for therapy. In the last two sections, a comparison with circular accelerators and an overview of future projects are presented.