Planet formation starts with disks of material around young stars that are spinning too rapidly to fall into the star. Large, gaseous planets like Jupiter and Saturn must form rapidly in these disks because the gas they require is otherwise lost in a few million years. Dusty material can remain for longer. When dust grains encounter each other, they often stick together and the result is that larger and larger bodies grown in the disks. Eventually, the encounters are not so gentle - large collisions shatter the objects that are forming, but much of the material is drawn back by the gravitational fields and some of the rest is accreted through more gentle encounters later. In this way, planets like the earth can grow over a period of a hundred million years or so. Any light gases remaining in these objects tend to escape because of their small gravities and proximity to the star (so they have warm atmospheres).