You have two choices:
1. Set up an indoor trainer so your front wheel is elevated about four inches. This puts your bike, and hence your body, in a position similar to what you'd experience on a real climb. This is important because the way you pedal and the muscles you use to support yourself on the bike are slightly different when you're going uphill. You need to get used to riding at a high sustainable power output in this position, rather than just focusing on developing power riding flat and hoping all that power will be accessible once you start going uphill.
2. Ride into a headwind. While this will not give you the same body position as elevating the front of the bike, riding into a stiff headwind helps build climbing strength by making you pedal against increased resistance at a relatively low speed. You can ride at high power output on flat ground, but that typically results in high speed and high cadence. Against a strong headwind, you're more likely to be pushing a lower gear at a lower cadence and not going very fast, despite a high power output. This scenario sounds a lot like climbing a big hill, doesn't it?
It's important to realize, however, that the most important thing you can do to improve climbing power is to work on intervals that increase your maximum sustainable power. Even if you're training primarily on flat ground, a great deal of the fitness you gain will transfer just fine to riding uphill. The climbing-specific techniques and body positions will help you go faster uphill, but these adaptations are secondary to gaining aerobic fitness.
Support Outside Online
Our mission to inspire readers to get outside has never been more critical. In recent years, Outside Online has reported on groundbreaking research linking time in nature to improved mental and physical health, and we’ve kept you informed about the unprecedented threats to America’s public lands. Our rigorous coverage helps spark important debates about wellness and travel and adventure, and it provides readers an accessible gateway to new outdoor passions. Time outside is essential—and we can help you make the most of it. Making a financial contribution to Outside Online only takes a few minutes and will ensure we can continue supplying the trailblazing, informative journalism that readers like you depend on. We hope you’ll support us. Thank you.