Repairing a door that doesn't latch properly might seem like a quick and easy door repair, and it can be, but there are a few little tricks that make the job much easier. When a door doesn't latch properly, it's usually because the door has sagged in the opening, making it so the strike doesn't line up with the hole in the jamb of the door, called the strike plate mortise.
To know if that's the case, you can typically just look at the strike plate to get an idea of whether or not things are lined up properly. You'll notice that the metal will be worn where the strike hits; if this worn area doesn't line up with the middle of the strike plate, it's out of alignment.

Try the easy stuff first
Before trying any fancy repairs, start by making sure the hinges are tight. If the hinges are loose, the door will sag. The fix is to simply tighten the screws; that's the easiest fix you could hope for. If the screws are stripped out, continue reading.
If the door strike almost lines up properly but it's off by just a little bit, there's a trick to sometimes persuade the door back into place without much effort. Simply remove one of the smaller screws from the uppermost hinge and replace it with a big 3" screw. Use an impact driver (or a drill if you don't have one) to drive this screw all the way through the jamb and into the framing at the side of the door. Sometimes this will be just enough to pull the door back into working order. If that doesn't do it, the next step is to reposition the strike plate.
Reposition the strike plate
The tricky part about repositioning a strike plate is that something will need to be done with the old screw holes. The new position of the strike plate will typically be about 1/8" lower, which means there is a good chance that the new screws will want to drift over into the old screw holes, making for loose hardware. Of course, you could always just put some monster 3" screws in the strike plate and hope they don't drift, but there's another less aggressive way of doing this that I prefer.
For this example, I've taken photos of the strike plate on a new exterior door that I installed at my own house. The problem with my strike plate was that I installed it just a hair too close to the frame, making it so my door latched too tightly. This was good from an air leakage perspective, as the weatherstripping made a very tight seal, but with the weatherstripping pushing against the latch, my kids couldn't open the door from the outside. It was too tight. The fix for this was to move the strike just a little bit away from the door. See below.