Shut off the water or gas supply. Use two 24-inch wrenches to turn the old union off of the pipe, using WD-40 if needed to loosen the joint. If the pipe union is damaged, use a reciprocating saw to cut the section of pipe where it is broken or leaking.
Measure between the ends of the two pieces of pipe that are left after you removed the pipe union or cut the section off. Buy one pipe union that fits the diameter of your pipe if that is all you are replacing OR buy two pipe unions and a piece of pipe with threads that is the length between the pipes you measured plus one inch if you cut off the pipe piece.
Put a drop or two of light oil on the threads of the old piping to make for a better union seal. Place the pipe union in place and tighten as much as you can with your pipe wrench. Make sure the male side of the piping is upstream and female downstream to insure that the water flow is smooth and will not erode the seal. Tighten the second end of the new pipe with the second pipe union, if you are replacing the pipe section.
Test the pipe union seal for leaks. Mix two cups of water with five drops of liquid dish soap, and then proceed to take a soft brush and spread the solution around the pipe union. Turn water or gas supply on and look for bubbles. If there are bubbles, this indicates a leak, so turn the supply off again and tighten the seal a bit more.
Turn the water or gas supply off if there is still a leak. Loosen the pipe union with the wrench and apply pipe joint compound or wrap Teflon tape around the pipe threads. Retighten the pipe union and test for leaks again.