I've not had much opportunity to go hiking for any decent distance recently and I feel the next time I do my body will probably complain a lot. However, I've access to a gym with a lot of equipment so what exercises and equipment should I be using regularly to ensure my first hike back is lacking in pain?
Train by hiking, start small, do it every week.
After my injury, when I could not hike, I started by hiking less than a mile, but I did it every week. Even only once a week, this will help. Pick a trail that's a length just a little hard for you. This is best if you have a nearby park with lots of interlocking trails. Interlocking is good because you can mix and match the path to increase distance.
Increase distance before you increase weight. I would not recommend adding weight until you can hike 5 miles comfortably.
Once you get to 5 miles, start carrying an empty pack. Next add your layer clothes (maybe it's cool enough for a jacket, but not needed when you warm up) Next add just a water bladder for drinking. To the extent that you can, I recommend packing things you will actually hike with. One, the weight is more representative, and two, the weight is going to be dispersed more realistically for actual hiking. If you train with other things in your pack just for weight you are more likely to train for a pack that's off balance.
Buy and learn how to use hiking poles. They really do help, even starting out.
If at all possible, exercise doing something you like, or in a place you like. If training is just misery you go through to learn to hike, you're less likely to train (and hike). Pick the day, time, and place that you are least likely to skip every week. Pick someone to go with you who will encourage you to never miss a hike.
If you seriously overweight, I would suggest first shedding the pounds by taking up swimming. This will greatly reduce the strain on your knees.
Like others have said, the best training to hike is hiking.
If you are concerned about being able to climb large vertical distances (mountains?), try climbing stairs. I don't mean the stair-climber at the gym (although it does help), but put on a pack with weight and find a tall building. Clear this with any security the building may have (or management/owner), and climb the fire stairs for a half hour. Once your body starts to acclimate to the challenge, increase the time that you climb the stairs.
As others have mentioned, the best exercise you can get is simply hiking. To train for weight, it's recommended to fill the backpack with water or sand that can be thrown out at the top to prevent knee injuries.
If you live in the flatlands like I do, there's not much elevation changes. The closest in the gym is to use an incline treadmill or a stepmill. I've even filled up a bag with weights to use on the stepmill.
As for specific weightlifting exercises, hiking requires a lot of lower body strength and endurance. Various squats and deadlifts can help strengthen your quads, hamstrings, glutes, and back.
General cardio (running, biking, or swimming) is always helpful since it'll build endurance, and if you can shave some pounds off your body, that's less weight you have to carry.
Alpine Ascents has a training program to prepare for Denali, which, while a little bit overboard for hiking, still shares the same concepts.
Body Results also has provides some mountaineering training DVDs which also share similar concepts.
It all depends on how far you want to hike! Its probably good to do stretching before any exercise such as hiking or running! Lunges and squats may also help as well.
Although you may look a bit silly in the gym, you could carry a backpack on a treadmill and use it on an incline to strengthen your legs.
I would also considering doing short burst of jogging as well to get your endurance levels up.
There’s no better hiking excercise than hiking :) Seriously, if you can walk to work, with your dog, to the shop, do it. Regularly. If you have some time during the weekend, go out for a few kilometers. Running is also fun, and depending on the weather where you live, you could easily run through the whole year.
Running will build up some strength in your feet and prepare your whole body to take the load, especially the heart and the lungs. Swimming works like that, too. I’d certainly take any “natural” activity rather than stay in the gym (but that’s just my opinion, of course).