Trial and error.
I was a player for a while first (a year maybe?) and then the DM wanted to play, so I DM'd.
I was terrible. I did learn from my mistakes (more slowly then, I was 10 or 11 or so).
Eventually during the next year, I got to begginer GM state- knowing the rules, and able to implement a prepared module.
I quit playing around 15 (discovered other hobbies- like girls and sports).
I started playing 2E many years later. I had to relearn to beginner GM state and graduated to intermediate GM- knowing the rules and implementing prepared modules with flavor, when the characters went off the track I could wing it. I could make my own scenarios, but they werent very balanced. I also had some problems with player problem resolution.
Then during 3E revival I feel like I finally made it to a full fledged gm. I know the rules, I can implement prepared modules, I can make my own, I can add flavor, I know how to resolve basic player problems, I can try to make sure everyone is engaged and having fun.
I would say the greatest tools for making it to each stage are:
Stage 1, beginner: reading the big three: PHB, DMG and MM- knowing the rules. Reading and running a couple of prepared adventures is excellent too.
Stage 2, intermediate: all of beginner stage, making up some scenes and scenarios, balancing tough parties, and practicing winging it. Reading things like Dungeon magazine and the dungeon craft articles are important. Also Robin's laws of good gamemastering or DMG 2 is good to read here. You should get some experience running games. Being able to produce stat blocks and adjudicate rulings on the fly is good here (prepared or on the fly is fine).
Stage 3, full GM: things to read here: any history books, how to win friends and influence people by Dale Carnegie, review Robin's laws of good game mastering, and any kind of personal relations material- because at this point you've probably mastered the technical part, and it is all people skills and from here on out (besides maintaining your technical skills).
-E