The 61-year-old is expected to make "a swift and full recovery" but assistant boss Russell Milton will be in charge of the Robins until Johnson is ready to return.
The former Yeovil Town and Northampton Town boss was admitted to hospital last weekend having missed Cheltenham's game at Doncaster Rovers suffering from what was thought to be a heavy cold.
Johnson said in a message to fans: "I'm sorry to say that at the present time, after much consultation, I am going to need heart surgery. The timing is obviously not the best but it is out of my control.
"I'm told that I'll be fighting fit within the next few weeks. Until then I ask politely for everyone; The board of directors, management staff and fans to come together as they have been all year to support our team.
"It is a young team and positive support will be vital in the next few weeks. The squad is good enough to succeed and we can put our faith in them as well as trusting Russell and the management staff to see us through this period.
"Be back soon, Gary Johnson."
Robins chairman Paul Baker, whose club are seven points above the relegation zone, said in a statement: "We wish Gary a full and speedy recovery from his operation and we will be offering our full support to him and his family over the next few weeks.
"The most important thing is that Gary returns to full health and the backroom staff led by Russell are more than capable of running things in his absence.
"We look forward to welcoming Gary back once he has been cleared to return to work but, realistically, this may take some time but the board will give Gary their full support in his recovery process."
Cheltenham were promoted into League Two from the National League last season.