The visitors dominated the opening half and led 12-3 at the break through tries from Andy Beattie and Lee Mears.
Chris Malone added a penalty and a drop goal for Bath but a try from James Bailey put Gloucester back in the game.
Although Gloucester's Ludovic Mercier spurned a superb chance to score, Mark Foster crossed late on to set up a grandstand finale but Bath hung on.
Bath head coach Brian Ashton
"We are not disappointed at winning 18-15 against any opposition. "We spluttered a bit in the first 30 minutes but it was a massive performance for 40 or 50 minutes of the game.
"I think it took a lot of courage to play the way we played for the first half. We carried on where we left off in the Wasps game and it's good to do it away from home.
"Hopefully we can use it as a springboard to say that we can do it both at home and away in the future."
Gloucester: Goodridge; Bailey, Simpson-Daniel, Keil, Foster; Mercier, Richards; Collazo, Elloway, Powell; Eustace, Brown; Boer, Hazell, Balding.
Replacements: Fanolua for Keil (51), Wood for Collazo (72), Forster for Powell (75), Pendlebury for Eustace (69), Amor for Boer (75), Narraway for Balding (53).
Not Used: Parkes.
Bath: Stephenson; Higgins, Crockett, Maddock, Bory; Malone, Walshe; Flatman, Mears, Filise; Hudson, Short; Beattie, Lipman, Fea'unati.
Replacements: Dunne for Stephenson (64), Finau for Bory (23), Loader for Flatman (72), Fidler for Short (72).
Not Used: Dixon, Scaysbrook, Fulton.
Att: 12,500
Referee: D Rose (RFU).