Do the following (assuming that cable is detached from the derailleur):
Adjust high/low limit screws.
Pedal bike so chain & derailleur end up in "normal" position. This will either be the largest or smallest gear depending upon type of derailleur. If you don't end up at one of these extremes, then at least one of the limit screws are not adjusted correctly (or something is wrong with your derailleur.)
Adjust shifter so that all of the cable is out.
Turn barrel adjuster nearly all the way in.
Pull cable taut and tighten screw holding it in place.
Press shift lever one or more times (to pull cable in) without pedaling. This will cause the housing to be fully seated into the ferrules.
Use barrel adjusters to adjust shifting. (If you do all of the above, not much fine tuning will be required.)
Don't overdo it on pulling the cable taut. The barrel shifters are used to fine tune the tension and you should have plenty of adjuster to work with so long as you screw the barrel adjusters all the way in (clockwise) prior to attaching the cable.
If you skip the step for seating the housing in the ferrules, chances are good that you'll need to adjust the derailleur after your next ride. Some people think that the cable stretches. It's more likely that the housing is getting better seated in its ferrules. Regardless, so long as you do that step, you'll be prestretching the cable as well as seating the cable into its housing.
A forum community dedicated to Mountain Bike owners and enthusiasts. Come join the discussion about bike parts, components, deals, performance, modifications, classifieds, trails, troubleshooting, maintenance, and more!