Regular use of your bicycle’s gearing system causes wear on the cables in two main ways. The first is by friction on the cable at points where it touches other cables, the bicycle frame or enters cable housings at a sharp angle. This can lead to frayed and bent cables. The second way cables are weakened is through rust caused by exposure to the elements. In either case, the safest thing you can do is replace the damaged gear shift cable immediately.
Shift the derailleur that leads to the cable you are replacing to the smallest sprocket. Cut the end cap off of the cable and loosen the nut on the derailleur that holds the cable in place using a 9 mm wrench.
Sketch out how the cable is threaded through the housings on the bicycle frame, particularly around the bottom bracket. Bicycles made before the 1980s typically thread the cable over the bottom bracket, while those made after typically go under.
Remove the cable from the derailleur and housings. Loosen the adjustment bolt on the brake lever using a 5 mm Allen wrench. Wiggle it toward the center of the handlebars so it is away from the gear shifter.
Crank the shifter to the lowest gear if you are replacing the cable to the front derailleur or to the highest gear for the rear. Locate the bolt that holds the shifter housing together and loosen it using a 2.5 mm Allen wrench. Only loosen it enough to open the shifter housing, but not enough to remove the bolt completely.
Carefully pull the shifter apart to expose the existing cable inside. Do not remove any components from inside the shifter or you risk causing permanent damage. Sketch on a piece of paper how the shift cable sits inside of the shifter. Unwind the old cable inside the shifter, slide it out and remove it from the bike.
Grease the grooves inside the shifter where the new cable will sit. Insert the open end of the new cable into the shifter body and pull it through until the nut end is settled into its appropriate slot. Loop the new cable around the inner grooves, checking your sketch to ensure that it is replaced exactly how the old cable was.
Thread the cable out of the bottom joint of the shifter body and pull it tight to settle it in the grooves. Push the two portions of the shifter body back together and test the shifter to ensure it is pulling the cable properly. Tighten the housing bolt to hold the shifter together and return the brake lever to its original position.
Drip a small amount of light viscosity oil into each of the cable housings. Thread the cable through each housing and then check your sketch of how the housings followed the frame of the bike to the derailleur. Replace the housings as they were before and pass the cable through the pinch bolt in the derailleur.
Pull the cable tight with one hand and tighten the pinch bolt with a 9 mm wrench to secure it in place. Cut off the excess cable so only 2 inches remain after the pinch bolt. Slide the end cap onto the cable and gently crimp it onto the cable using a pair of pliers.
Pedal the bicycle and cycle through the gears. Turn the shifter barrel adjuster tighter or looser to fine tune the gears until the cable shifts smoothly through all gear combinations.