The old rules stated that you would have to reinvest.
The new rules (relatively new, but have been around for years..) state that you get 500k tax free gain if you are married, 250k if single if you meet certain conditions. You must have lived there as a primary residence for 2 out of the past 5 years. EG: If you lived there the past 2 years, you are OK. If you lived there 2 years, rented 2 years, and now want to sell, you are OK. When you sell, you get the proceeds and can do whatever you want with them. On your taxes for the year of sale you will pay nothing on the gain if you meet the conditions. If you don’t meet the conditions, there are other options that a CPA can talk you through.
Note: I am not a financial expert, so check with a CPA, but I did sell for a gain last year.