You should be able to do this, if you get the mounting hardware for the double din that is fit to your year/model of Xterra. The wiring, assuming that the previous owner didn't do a hack job will most likely consist of an adapter plug that was custom fit for the xterra on one side and has open wires on the other. These wires are then spliced to the plug that comes with whatever radio that they put in. You may get lucky if your new radio is the same model as the old one that the plug on the back side of it matches. If it does not match all you need to do is separate the wiring harness that comes from the head unit from the wiring harness adapter that plugs into the xterra, and re-wire that to the new wiring harness coming from your new head unit. The wires coming off the aftermarket adapter are generally color coded to match the standard colors coming off the plug in the new head unit, so it should be red to red, blue to blue, black to black kind of splicing. I advise that you take the time to do it right, use good quality but connectors and heatshrink tubing if you can, it isn't "necessary" but it is best practice.
If it is a hack job where they cut the factory plug off, and hard wired the aftermarket plug into the wires already in the Xterra then the procedure is basically the same as the one I described above, but you need to make sure that you know the color code of the wires for the unit that you will be splicing. You should be able to find a wiring diagram somewhere in the forums for your year and go off of that.
Lastly there are definitely good and bad electrical tape brands, I prefer 3M or scotch, don't waste your time with the harbor freight rolls, they get brittle quick and don't stick well when they are cold.