In the Ramayana, we know that Ravana was the King of the golden city of Lanka. How did he get this city? I know very little other than that it was offered by Shiva.
The story of Lanka is described in detail in the Uttara Kanda of the Ramayana. (The links in my answer link to different excerpts from the Uttara Kanda.) There were three Rakshasa (demon) brothers named Sumali, Mali, and Malyavan who obtained a boon of invincibility from Brahma and then told the divine architect Vishwakarma, "Erect a mansion for us resembling the mansion itself of Maheshwara [i.e. Shiva]." So on the island mountain Suvela, Vishwakarma "construct[ed] a city of Lanka there, having an area of thirty yojanas, and measuring an hundred (sic) in length; surrounded by a golden wall and furnished with golden gateways ... having a strong wall and a moat, abounding in hundreds of golden edifices". But then Vishnu defeated the three brothers, killing Mali and driving Sumali, Malyavan, and their Rakshasa comrades away to Patalaloka (the netherworld). Since Lanka was abandoned by the Rakshasas, when Kubera son of the sage Vishravas was made the god of wealth, he moved into Lanka at his father's suggestion.
Later on, the demon Sumali I mentioned earlier got his daughter Kaikeshi married to Kubera's father Vishravas, and they had many children including Ravana. Ravana got a boon of near-invincibility from Brahma, so at his grandfather Sumali's urging he attempted to retake Lanka for the Rakshasas. When Kubera heard that his half-brother Ravana wanted to move into Lanka, he was more than happy to have him, saying this:
My father had given [Lanka] to me, when it had been emptied of Rakshasas; and ... I have inhabited this place, furnished with charity, honor, and other virtues ... [A]s this city and kingdom are mine, so they are thine, O mighty-armed one. Do thou enjoy this kingdom without a foe. May my kingdom and wealth never undergo division when thou art present.
But Ravana wasn't willing to share the kingdom; he wanted it exclusively for him and his fellow Rakshasas, so Kubera at his father's suggestion abandoned Lanka and went to the Himalayas. That is how Lanka came to be under Ravana's possession. (Contrary to popular belief Ravana did not fight Kubera over Lanka; like I said he got Lanka without a fight. The battle between them happened later, when Ravana was attacking everyone under the sun in his attempt to take over the three worlds. It was during that battle that Ravana defeated Kubera and took the Pushpaka Vimana.)
There are many variations to this story, few include Shiva and few do not.
According to one story, after getting jealous with Devi Lakshmi's house, Devi Parvati demanded a better house for her. Lord Shiva first refused but later completed her wish and asked Vishwakarma to build a house which will be better than any existing house in the universe. So Vishwakarma built the Golden House (Lanka). But as per tradition for griha pravesh, they asked for a rishi to do a pooja. This rishi is no other than Ravana's father Vishrava (in some version of stories Ravana does the pooja by himself). Ravana's father was not greedy but his wife manipulated him to ask Lanka in dakshina. And when Shiva or Parvati asked him for his demand, he asked Lanka. They gave him Lanka but cursed the Lanka and the rishi. So Ravana got Lanka through inheritance.
There are some contradictory stories too where Kubera, son of Vishrava is the first owner of Lanka. And another story says Sumali is first owner of the Lanka (not Shiva).
Refer this forum for the user who submitted the story of Lanka.