Unless your home was your primary home for at least 2 of the last 5 years (not necessarily 24 consecutive months), you'll be required to pay capital gains tax on the gains. See Publication 523, specifically the "Eligibility Test". There are some exceptions, but you'll need to review the rules yourself to see if any of them apply.
https://www.irs.gov/pub/irs-pdf/p523.pdf