I learnt it over a period of years mostly by self-study but also by using meditation to revive knowledge of Sanskrit from previous births. However, the interest in Sanskrit could be divided into two parts, learning vocal Sanskrit and learning literary Sanskrit. Just as a person can be fluent in English and still fail an English grammar and usage exam, the same goes for any other language. A person may be expert in writing English language and be terrible at pronouncing English words because of not being exposed early on to the correct vocalization of the language.
The point is to make a decision as to if one wants to learn to speak Sanskrit or to translate from Sanskrit. To learn to speak it one should have access to a pandit or someone who speaks it fluently and one must also learn the alphabet, which is quite different to the layout in English.
If one wants to understand Sanskrit literature like Bhagavad Gita or Yoga Sutras, then one should learn the grammar regarding the breakdown of nouns, verbs and other features of the language.
This seems to be a big task but it is encouraging to know that it is a dead language, where it is not increasing in vocabulary like say English. Sanskrit has root words (dhatus) which are in a limited number. If one carefully studies these, one can easily master the language because the combinations of these root syllables makes all the words in the language.
One thing that helps with the Sanskrit texts is to get translations which have word-for-word meanings because then one can compare them and learn quickly. Translations without that are useless to check the meanings of the words and compare one translation to another.
One book worth mentioning is the Bhagavad Gita by Winthrop Sargeant. It is the only I know of which has the exact grammar designation of every word of the Gita. I translated Bhagavad Gita and gave Word-for-Word meanings but his detailed grammar designations are unique.