How does one attain the specific heavenly realms situated above Earth?
One way is by following the various dharmas of the different castes. If a member of a particular caste fulfills his caste duty, he will by default go to that particular realm that is a reward for following his varnashramadharma.
From the Vishnu Purana:
The means of subsistence having been provided for the beings he had created, Brahmá prescribed laws suited to their station and faculties, the duties of the several castes and orders, and the regions of those of the different castes who were observant of their duties. The heaven of the Pitris is the region of devout Brahmanas. The sphere of Indra, of Kshatriyas who fly not from the field. The region of the winds is assigned to the Vaisyas who are diligent in their occupations and submissive. Śúdras are elevated to the sphere of the Gandharvas. Those Brahmanas who lead religious lives go to the world of the eighty-eight thousand saints: and that of the seven Rishis is the seat of pious anchorets and hermits. The world of ancestors is that of respectable householders: and the region of Brahmá is the asylum of religious mendicants. The imperishable region of the Yogis is the highest seat of Vishńu, where they perpetually meditate upon the supreme being, with minds intent on him alone: the sphere where they reside, the gods themselves cannot behold. The sun, the moon, the planets, shall repeatedly be, and cease to be; but those who internally repeat the mystic adoration of the divinity, shall never know decay.
These worlds, some of which will be more particularly described in a different section, are the seven Lokas or spheres above the earth: 1. Prájápatya or Pitri loka: 2. Indra loka or Swerga: 3. Marut loka or Diva loka, heaven: 4. Gandharba loka, the region of celestial spirits; also called Maharloka: 5. Janaloka, or the sphere of saints; some copies read eighteen thousand; others, as in the text, which is also the reading of the Padma Puráńa: 6. Tapaloka, the world of the seven sages: and 7. Brahma loka or Satya loka, the world of infinite wisdom and truth. The eighth, or high world of Vishńu ..... is called Vaikuntha.
However, according to Ranga Ramanuja, a Sri Vaishnava commentator on the Upanishads, Gandharvaloka is in Antariksha loka, also known as Bhuvarloka (and not Mahaloka, which is the realm of saints), which is situated below Swarga and above Earth.
Who inhabits each of these heavens?
This section of the Vishnu Purana says:
Above Dhruva, at the distance of ten million leagues, lies the sphere of saints, or Mahar-loka, the inhabitants of which dwell in it throughout a Kalpa, or day of Brahmá. At twice that distance is situated Janaloka, where Sanandana and other pure-minded sons of Brahmá, reside. At four times the distance, between the two last, lies the Tapo-loka (the sphere of penance), inhabited by the deities called Vaibhrájas, who are unconsumable by fire. At six times the distance (or twelve Crores, a hundred and twenty millions of leagues) is situated Satya-loka, the sphere of truth, the inhabitants of which never again know death.
The translator also adds a very lengthy footnote to that passage.
The other way is by doing the specific yajnas and upasanas mentioned in the Vedas that reward a specific fruit. For example, king Pururavas did a specific yajna to reach Gandharva loka:
Having thus determined, he took the plants to his city, and prepared their wood for attrition, with pieces of as many inches long as there are syllables in the Gayatrí: he recited that holy verse, and rubbed together sticks of as many inches as he recited syllables in the Gayatrí. Having thence elicited fire, he made it threefold, according to the injunctions of the Vedas, and offered oblations with it, proposing as the end of the ceremony reunion with Urvaśí. In this way, celebrating many sacrifices agreeably to the form in which offerings are presented with fire, Purúravas obtained a seat in the sphere of the Gandharvas, and was no more separated from his beloved.