It was presented to him when he turned 20 and learned of his heritage. Elrond (who, as you remember was there when Elendil fell) took the sword up and kept it safe in Rivendell. Aragorn was brought to Rivendell as an infant when his father was killed. Elrond raised him as his own child. At the age of 20, Aragorn met Arwen for the first time and asked Elrond about her. Elrond told him all about his history and told him that the only way he would be worthy of Arwen's hand would be to reclaim the throne of Gondor. He presented Aragorn with the shards of Narsil (which he carried with him from that day forward and was wearing it the first time he met Frodo and Co) and Aragorn spent the next 67 years working toward reclaiming the throne of Gondor. Everything he did, every step he took, was with that purpose in mind.
Aragorn is the direct descendant, father to son, of Isildur (Elendil's son), making him the rightful king of Gondor.