The Frenchman has also claimed that Madrid coach Zinedine Zidane attempted to convince the 30-year-old to move to Los Blancos.
"Barcelona and Madrid are very big teams and there was a moment when both teams were interested in me," Ribery told beIN Sport.
"I liked both but I had a moment in which I felt closer to Madrid than Barcelona. Zidane wanted me to go to Madrid and he tried all he could. But I am not interested now because Bayern is my family."
Ribery scored 11 goals last season as Bayern won a domestic double and the Champions League.