Since making his club debut in 2001, Barkley has established himself as the cornerstone of Bath's backline, amassing 1538 points in 164 appearances. He will join up at Kingsholm in July with former Bath team-mates Gareth Delve, Mike Tindall and Iain Balshaw.
"Bath has played a massive part in my life for a long time - not just as a rugby player but also as a person - and I would like to thank everybody involved," Barkley said.
"This was not an easy decision to make and I am determined to leave the club on a high at the end of the season. We are challenging strongly in the Premiership and hopefully we can bring some silverware back to the Rec.
"When you look at the training facilities at Hartpury College and the stadium developments at Kingsholm, it is clear that Gloucester is a club that is going places. I look forward to playing my part next season and establishing myself in the squad."
Barkley, who was nominated for the Premiership Golden Boot award in 2006/07 following a personal haul of 264 points and was a member of England's 2007 World Cup squad, has so far made 13 appearances in all competitions this season, scoring 116 points.
Dean Ryan, Gloucester's head coach, said: "We were looking for an experienced back to enhance our squad for next season and Olly fits the bill perfectly. He is a skilful runner, clinical kicker and versatile enough to play at international level in more than one position.
"Olly recognises that he will have to work exceptionally hard to earn his place in the Gloucester team owing to the strength of our existing squad, but that is one of the reasons we wanted him - he has a great attitude and will not shy away from the challenge.
"This signing reinforces our desire to create a competitive environment at Gloucester with outstanding young talent at its core, which can only be good for the future of the club."