Capital gains

For the primary residence exclusion, do I have to live in the home 2 of the first 5 years of ownership. Do I have to own the home for 5 years or just live in it for two. Also do the years have to be consecutive?