A gym, short for gymnasium is a facility for physical fitness. Gyms were often a standard facility that were incorporated into many Starfleet facilities and starships, and would often come equipped with a variety of equipment for use when exercising.
Aboard Federation starships, the gymnasium was also an essential part of the recreational facilities that were offered to crewmembers. As well as the recreational uses, the gyms aboard starships were also used for training purposes, usually by the security division. The USS Enterprise's gym featured gravity weights which in 2254, Christopher Pike exerted himself using whilst grieving for his recently deceased yeoman, Dermot Cusack. (EV comic: "Nor Iron Bars a Cage")
In 2266, James T. Kirk took Charles Evans to the Enterprise's gym to practice some unarmed defense moves. Kirk hoped that the violent exercise would help take Charlie's mind off Janice Rand, in an old method practised by men in Victorian England. (TOS episode & novelization: Charlie X)
Following a fight between Doctor Carter Greyhorse and Gerda Asmund in the corridors aboard the USS Stargazer, the two both agreed to meet in the Stargazer's gym at least three times a week so that Gerda could train him in Klingon martial arts. (STA novel: Gauntlet)