Shanks probably deceived Gorosei into telling him the information about Nika fruit without them realizing it. He may had tracked that fruit his entire life and studied that WG apparently has pattern, frequency, location of transporting that fruit to different location every few days or something. Stealing it once he studied that its guards are the weakest or most corrupt so that he bribed them using valuables or even other Devil Fruits, distracted the guards (Whos Who at that point) with creating an urgent commotion not far from the fruit's location, and even made it so that distracting assault involved the guards' family or even better, involved Celestial Dragons being abducted and made hostages. Using bribery and that level of distraction no marines will ever avert their eyes from, Shanks came taking the fruit for himself, since only he had to ensure that it was really Nika fruit and not a replica made for deception. Shanks used his Conqueror techniques and heard the voice of Nika, confirming all he needed to know about the fruit's true identity.
The Red Hair thought of eating the fruit himself but he wasn't sure about whether he was the one being fit to use this kind of imagination-oriented power. Afterall, he was just a man full of tactics and deceit. His action was always based on logic and use others for his benefits without soiling his hands if he can manage it. His lack of imagination and creativity in approaching each obstacles in life, his approach of seeing each chapters in life as a mission instead of a journey, all made him feel like he will not able to use the fruit's potential to the fullest. Especially in a war, where every habitual reflex count...the one worthy of wielding this fruit should be no one else than someone with the purest of heart. Someone who sees life as a treasure chest waiting to be opened, an impossible challenge ready to be surpassed, a horizon of endless adventure, instead of someone calculating like him. Someone like...his captain? Or even more! Only someone with such a dreaming and creative approach in life, will be enough to wield such an imaginative fruit.
Thus, Shanks visited Fuschia village. Only to find a brat that want to become a person with the most freedom in this world. Someone who wants to protect everything on his shoulders, to ensure the happiness of everyone he holds the most dear. A kid with untarnished dream and limitless sky of imagination in his heart. Someone who also said the same thing his captain said. Shanks used his Conqueror technique on Luffy, only to feel the chains of fate linked so inescapably between Nika fruit and this boy. These are two existences that completes each other so beautifully. It was so inevitable. So this is the one kid you sought all this time, Shanks said to the fruit of Nika. He felt Nika affirmed it while smiling so strongly.
Suddenly Shanks felt an ache in his heart. How can such a boy bear a responsibility to inherit such a grand will of Joy Boy? To come as a dawn that extinguish Imu, the God of Eternal Dominion above The Empty Throne?
From there, Shanks was determined. He would show this boy the weight of sacrifice and the burden he should bear. He told his crews to silently guard the treasure chest in the bar, so that no one can actually approach. Until Luffy set his stare on that mystery chest. Shanks activated his Conqueror Restrain and everyone in this bar even his trustworthy crew, had their senses temporarily annihilated, even their memory and sense of time. They could not see or feel anything. Except Luffy. Until Luffy had curiously opened the treasure chest and felt a calling from a mystery fruit to just take bite. Luffy took a bite. Then Shanks loosened his Conqueror restrain. Beckmann, realizing first about the gap in time of his daily life, questioned Red Hair for his odd actions, but he just sighed. No one else should know for now, Shanks thought.
And the next was how Shanks showed Luffy the burden of being a Pirate. Sacrificing his own limb to protect the ones precious to you more than your own life. Because Luffy is more precious to Shanks, even compared to Shanks' own life. This is Shanks' role, to be the first witness, as Luffy and Nika set the world ablaze with freedom once again.
Source: trust me bro