Drive the roll pin out of the gear, pull the gear and spacer/washer off. Pull the shaft out of the distributor housing. The cam position sensor then comes out with a screw. Re-assemble in reverse order. As long as it's apart clean the old grease off of the shaft and bushings, inspect it for excessive wear, (which usually there isn't any), and re-grease it before you put it back together.
Remember to take a sharpie and place a mark on the housing right off the end of the rotor (where it's pointing at) before you pull the distributor. Usually when you pull the dist, the oil pump will turn slightly and the dist won't drop back in all the way. You'll have to put a long straight bladed screwdriver down into the oil pump and index it slightly so the end of the dist shaft will line up with the slot in the pump when you have the right tooth engagement on the dist gear.
I think that's what you're asking, unless you're trying to put a distributor in a distributor-less engine.