How Arjuna acquired the celestial bow Gandiva is explained as under.
Lord Brahma advised Agni{Fire God} to consume the Khandava forest, as the dreadful forest, which was the abode of the enemies of the gods{and which Agni had once consumed to ashes at the request of the gods, earlier},had become the home of numerous creatures.
Lord Brahma also advised Agni to consume the Khandava forest for regaining his health. Agni had developed an illness due to excessive consumption of sacrificial butter.
At the sacrifice of king Swetaki, Agni had drunk clarified butter for twelve years. Indeed, clarified butter had been poured into Agni's mouth in a continuous stream for that period. Having drunk so much butter, Agni, satiated, desired not to drink butter again from the hand of anybody else at any other sacrifice.
Agni became pale, having lost his colour, and he could not shine as before. He felt a loss of appetite from surfeit, and his energy itself decreased and sickness afflicted him.
Agni made valiant efforts to consume the Khandava forest.But, Indra foiled the attempts of Agni by sending heavy downpours of water, as he wanted to protect Takshaka the Naga ,living in that forest.Agni tried seven times to achieve his objective, but each of his attempts met with failure as Indra foiled all of them.
Agni again approached Lord Brahma and informed him that all his attempts were getting foiled, due to Indra.Lord Brahma then informed Agni that Narayana and Nara had taken birth as Lord Sri Krishna and Arjuna. And Agni was asked to take the help of Arjuna and Lord Sri Krishna to consume the Khandava forest.
Agni then approached Arjuna and Lord Sri Krishna, who were resting near the Yamuna river and explained his problem to them.
Arjuna and Lord Sri Krishna agreed to help Agni. But,Arjuna,pointed out his requirements to Agni and said:-
I have numberless excellent celestial weapons with which I can fight even many wielders of the thunderbolt.
But, O exalted one, I have no bow suited to the strength of my arms, and capable of bearing the might I may put forth in battle.
In consequence of the lightness of my hands also I require arrows that must never be exhausted. My car also is scarcely able to bear load of arrows that I would desire to keep by me. I desire celestial steeds of pure white, possessing the speed of the wind; and a car possessing the splendour of the sun and the clatter of whose wheels should resemble the roar of the clouds.
Agni then paid his respects to Varuna and made the following request :-
Give me without loss of time that bow and quiver, and that ape-bannered car also, which were obtained from king Soma. Partha will achieve a great task with Gandiva.
Varuna then gave Arjuna that wonderful jewel of a bow{Gandiva} that was endued with great energy.
That bow was the enhancer of fame and achievements, and was incapable of being injured by any weapon. It was the chief of all weapons, and the grinder of them all. And it was the smiter of hostile armies and was alone equal to a hundred thousand bows. It was the multiplier of kingdoms, and was variegated with excellent colours. It was well-adorned, and beautiful to behold, and without a mark of weakness or injury anywhere. And it was always worshipped both by the celestials and the Gandharvas.
Varuna also gave two inexhaustible quivers, and he also gave a car furnished with celestial weapons and whose banner bore a large ape. Yoked unto that car were steeds white as silver of the fleecy clouds, and born in the region of the Gandharvas, and decked with golden harness, and resembling in fleetness the wind or the mind. And it was equipped with implement of war, and was incapable of being vanquished by the celestials or the Asuras. Its splendour was great and the sounds of its wheels was tremendous. It delighted the heart of every creature that looked at it.
As explained in the aforesaid paragraphs, Arjuna thus acquired the bow Gandiva, from Varuna,with Agni's help.
Reference-Mahabharata Book:1,Adi Parva, Khandava-daha Parva.