Living with a foreign family can be a good way to learn a language.
or
Live with a foreign family can be a good way to learn a language.
One of the tricky things about English is that many verb forms are the same.
Live can be an imperative
live well!
Or a present tense
I live in Egypt
Or an infinitive
I prefer to live near my family
Living can be an active participle
I was living in Tehran at that time
Or a gerund (verbal noun)
Living abroad is exciting
In your sentence, can be is a verb and requires a noun phrase as a subject. You can use a gerund or an infinitive to form a noun phrase:
Living with a foreign family can be a good way to learn a language
To live with a foreign family can be a good way to learn a language
The first (living) is the most idiomatic way of saying this.
Your basic structure is
[[Something]] can be [[something else]]
Subject - verb* - object.
What can be the subject of a sentence? Either a noun or a phrase that acts as a noun.
In this case the subject is going to be a gerund which is a type of noun made by adding -ing to a verb: Liv-ing. In this case, we think of living as a something - an abstract something, but a thing, not an action.
Living can be a good way to learn a language.
Now we have a fully grammatical sentence - but it doesn't really make sense. Not just any living is good for learning a language - we need to modify what kind of living it is. We'll turn the noun into a noun phrase by adding a prepositional phrase to it.
Living with a foreign family can be a good way to learn a language.
Note that since the noun is a gerund in this case, we could also call it a gerund phrase.
Live is a verb, not a noun, so it doesn't work as the subject of the sentence.
One other form that could have worked, if it were an option on the test is the non-gerund noun "life." This sentence would have a very similar meaning to the one that uses living:
Life with a foreign family can be a good way to learn a language.
* Can be is actually a modal verb phrase. Can is the modal verb, and be is the bare infinitive of the verb to be.
You could use live, but you'd need to restructure the sentence somehow:
Living with a foreign family can be a good way to learn a language.
Live with a foreign family – that can be a good way to learn a language.