Which preposition is correct and what is the difference in meaning if any?
I went to the gym, something I haven't done for a long time.
I went to the gym, something I haven't done in a long time.
Which preposition is correct and what is the difference in meaning if any?
I went to the gym, something I haven't done for a long time.
I went to the gym, something I haven't done in a long time.
Both are grammatical. There's no difference in meaning, but, at least in the UK, in a long time could be a class marker.
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
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