Question: how many years do you have to live in a home to avoid capital gains?
Answer: To claim the whole exclusion, you must have owned and lived in your home as your principal residence an aggregate of at least two of the five years before the sale (this is called the ownership and use test). You can claim the exclusion once every two years.