The chain and gears tend to be the most neglected part of a bike. Oh who am I kidding—most people neglect the entirety of their bike equally and completely. They just buy a new one when the old one stops working. However, if you take minimal care of the drivetrain, a halfway decent bike can last for decades. There are three keys to drivetrain longevity:

Most importantly oil your chain. Other parts of your bike tend to wear according to use. It takes quite a few miles to wear down your tires or brake pads, and when the time comes to replace them you won't get sticker shock. The drivetrain, on the other hand, wears proportionally to the amount of friction. Loud squeaky rust noises aren't just embarassing, they are costly as well.

Don't shift under load. When it's time to shift, pedal lightly. Pedaling hard has a tendency to make the chain jump and catch on the sprockets. You'll hurt your drivetrain, and you might hurt yourself.

Keep the derailleurs adjusted properly. If you hear the chain rubbing then it's going to wear faster than it should. The louder the noise, the faster the wear. It's worth noting that a new bike will need an adjustment after a few weeks due to initial cable stretching.