I suppose it's on a C-to-C basis. Carrier task force units in the Pacific would probably carry spare machine guns or barrels for auto-firing AAs since these could overheat. What about slightly bigger guns like 3- to 5-inch?
Concur. The smaller bore guns, say 40mm, could have spare barrels, but anything say 3 inches or larger needed a crane to swing a barrel out and a replacement in. Take a look at this 14" (?) gun mount. Note the people directly below the mount, barely visible in their black and/or grey coats.
Ship yard work. Speed wise it was faster to lift the barrel out (on the bigger ships it may require dismantling the turret by removing the turret roof), put in a fresh barrel with the one old getting a new liner (at the arsenal). Watervilet can do it for 16" guns. Highly doubt if even spare AA barrels were carried. It's one reason why ships go into a shipyard for refit - to fix things or upgrade the ship.
40mm barrels are all over the place on the USS Alabama, secured in racks on bulkheads, mostly in the superstructure.
Yes, all warships of the USN carried plenty of spare 20mm & 40mm gun barrels. The air-cooled 20mm would heat up rather quickly with continuous firing, so the hot barrel was swapped out after about 250 continuous rounds. There were water troughs located near the guns for such cooling purposes. The 40mm had a water jacket around the barrel, so they could fire for longer periods. They also had a barrel life of 9500 rounds or so, thus they were more often swapped out due to damage, than overheating or barrel wear.