Formal:
* Ich habe vor vielen Jahren Deutsch gelernt. (This is the most straightforward and formal way to say it.)
* Ich habe Deutsch vor vielen Jahren erlernt. (Similar to the previous option, but slightly more formal.)
Informal:
* Ich habe vor langer Zeit Deutsch gelernt. (This is a more casual and informal way to say it.)
* Ich hab' vor Jahren Deutsch gelernt. (This is even more informal, using the contracted form of "habe".)
* Ich habe früher Deutsch gelernt. (This literally means "I learned German before", implying that you don't speak it fluently anymore.)
Adding more detail:
* Ich habe Deutsch vor fünf Jahren in Berlin gelernt. (This adds the specific place and time of your German learning experience.)
* Ich habe mehrere Jahre Deutsch studiert. (This indicates that you studied German for a significant period of time.)
The best option for you will depend on the specific context and the level of formality you want to achieve.