I’ve observed if I say nothing (because I simply don’t know how to react), opinionated people think you agree with them, which I don’t. I don’t care.
what I want to tell him, next time he starts ranting: ‘I don’t care what you think, leave me alone’.
However, I may have to work with this person in the future, so what about ‘you don’t have to tell me everything you think, most of the time I don’t pay attention’ and if he keeps pushing it ‘it’s tiring working with a person who has to rant to feel good, it’s boring and makes me ignore you, which is a problem, because we work together.’ And leave.
What about ‘everybody has problems, maybe talk to a therapist? I cannot help you’.
Or maybe simply leaving when he starts his rants?
Yeah it is important to set boundaries. It’s critical, actually. But it need not be judgmental or cruel. Work is a place where I go to give my time and labor for money. It’s nothing else. I have friends, family, and a therapist. OP’s coworker may not, and that is sad. But their behavior is hurting OP, which means it’s time to set a boundary.