Should I replace my car battery?

I have a 2012 Honda Civic. I bought it used in June with close to 50 thousand miles. I don't drive it much (as its my second car and my old Volvo SUV uses a lot of gas but I still need the space) but I've only put on 2 thousand miles. It came with a lot of original parts and I've already replaced the tires, and brakes. I notice the headlights seem to dim and flicker often. Isn't that a sign of dying battery? Other than that the car always starts but I don't want it to die out in a sketchy part of town for example.

Battery life is usually 3-4 years. If your lights are flickering it's not the battery. That may be due to a loose or corroded connection.

Have the battery tested then you will know if you need to replace it.

If headlights dim it's got something to do with the charging system. Check the alternator belt, I had the same issue and it turns out to be the belt being all cracked up and it was "skipping" on the pulleys. Headlight bulbs dim over time so replace them too. If the belt is not your issue it's probably the alternator. Batteries should be replaced every 5-6 years and more often if you don't drive much. The local auto parts shop may give you a free charging system test if you buy a battery from them.