First thing is to make sure your engine is decoder ready.
Not all engines will accept or have space for one.
Make sure you buy the correct decoder for your engine and check inside the package for the detailed instructions.
It's not too difficult.
Dennis
Even a locomotive that is not "decoder ready" can have a decoder installed. You just have to remember that if the locomotive uses the frame as part of its power path that you must then insulate the motor from the frame.
If an engine doesn't have space for a decoder, don't overlook the use of an n scale decoder in an ho model. I have a p2k Sw that seemed to not have room for a decoder. I installe a m-1 decoder design for n scale on the inside of the cab ceiling. I did not try to install sound or any other function, just direction and stop start on the motor. I even wired the lights directly, because from my observations when a crew is switching, they turn on all of the lights and leave them on. The exception is if the switcher has a low nose like a Cf7 with a headlight on the nose, they will leave that headlight on the low nose turned off to avoid burning the switch man as he climbs on and off the locomotive.