"For a long time" vs "in a long time"
Solution 1:
Barrie's answer is correct for the case you used as an example. However, when referring to the future, only "for" is correct.
"I won't be going to the gym again for a long time" ← valid
"I won't be going to the gym again in a long time" ← incorrect
Solution 2:
Both are grammatical. There's no difference in meaning, but, at least in the UK, in a long time could be a class marker.
Solution 3:
We have been living here for a long time. (present perfect continuous) - It began in the past, and still lasts.
They lived in New York for a long time. (past simple) - The action began and finished in the past.
They will do it in a long time. (future simple) - It will begin and be finished a long time from now, in the future.
for a long time (present perfect (continuous)) - past - present - future
for a long time (past simple) - past
in a long time - future