How can a beginner cyclist build up power?
Keep on riding. Ideally every couple days. If you can't ride, do some other form of cardio exercise, such as going for a walk. I'll bet a couple days after that ride you'll find the same distance a little easier and might even be able to go a little further.
Get a day of rest. If you've pushed yourself really hard and you're "done", take a day off before getting back on the bike. (or at least before doing anything hard on the bike)
You may need to tweak the bike fit. Make sure you can inhale fully. Forward/aft position of the seat as well as vertical position of the seat can make a difference in power. Ball of your foot should be on the spindle of the pedal, when the pedal is straight forward your knee should be over the pedal, and at the bottom of your pedal stroke your leg should be near full extension (but still knee a bit bent). You shouldn't need to stretch your leg or rock your hips to reach the pedal at the bottom of the pedal stroke.
Build your leg strength, especially quads. Squats or leg presses.
Pay attention to your pedaling technique. Don't mash the pedals hard in a high gear. Move them faster in a lower gear, move your leg smoothly through the entire pedal motion and try to pull your foot up a little as it comes up, but without removing your foot from the pedal.
Interval training. This is the most important thing for building your endurance. Once you're warmed up, ride as hard as you can for 30-60 seconds, then ride easy for several minutes. As you build up endurance, increase from doing that once to doing that several times during a ride. If you can't do 30 seconds, do what you can.


Above all else: have fun riding. Don't torture yourself. Enjoy yourself. If you have fun you'll keep it up and keeping up the riding will make more of a difference than any small details.

So that's the "thorough" version.  But Neil Fein's version covers it pretty well:


  Ride often. Rest. Repeat often.


Have fun!