Is it a backhoe boom, or a loader? Not that it matters a lot, but it is a tad confusing.
First, make sure it is sitting on the ground. No pressure due to gravity. If it is a backhoe boom, support the boom on blocks or hold it up with a cherry picker or equivalent. Then with the engine off, cycle the controls several times to release any hydraulic pressure. Then slowly loosen the hose connections. You can put an old towel over it if you are concerned about it squirting, and you will need a bucket under it to catch the drippings. Unhook the hoses, put caps into the cylinder holes and onto the hoses to keep dirt out. Take out the pins and remove the cylinder.
Set up the new cylinder to the length of the old one, so it will fit. It will be hard to move and you may have to use a come along or ratchet strap to pull it out. I use a engine hoist (cherry picker). Put the cylinder in place and insert the top pin (so it will hang down on it's own). Move the boom or loader to get the bottom pin to align with a hoist, floor jack, etc. DON'T use your finger to feel it, many people can only count to 9 due to that!!! If you can't move the loader / boom, hook up the hoses and use the hydraulics to extend/retract the cylinder to fit. You may have to extend and hold the control then retract and hold the control to purge out the air. Air in a dry cylinder makes them "jumpy" and hard to move small amounts.
What went wrong with the old cylinder? Bent? Leaking? or??
jb