Earth was able to retain an atmosphere because of its gravity. The Earth has a gravity that is forceful enough to retain its atmosphere (which is six times than the moon's) and has the ability to block the solar wind that will probably strip the atmosphere off.