To be able to avoid capital gains tax you need to live in your home for at least 2 years before you sell it.
You do not have to live in the property for 5 years before selling it to avoid capital gains tax but you need to live in the home for 2 years minimum before you sell it to avoid capital gains tax.
The longer you live in the home the better when it comes to capital gains tax but as long as you live in the home for a minimum of 2 years you avoid capital gains tax.
You reach capital gains exemption after living in the home for 2 years but the longer you live in the home the better.
If you at least own the home for 5 years before selling it then you can also possibly make more money on the sale of the home when the home increases in value as well.