One shouldn’t live in a neighborhood which has groups of people constantly congregating and speaking lashon hara, baalei lawhon hara. This is based on a Rambam which quoted the Mishna in Pirkei Avos 9:1 that says, “Woe to the wicked and woe to their neighbors.” This quote was also mentioned by Rashi in reference to Korah and the tribe of Reuvein. One definitely shouldn’t join the group even if he will tell himself, he won’t accept anything he hears because just lending an ear to listen is forbidden. What’s even worse is to sit in shul in an area where people are talking and speaking lashon hara during davening because not only are you listening and probably joining into the conversation, but you might very likely miss answering by kaddish, amens, barchu, listening intently to the Torah reading etc. Also, to sit with shmuzers in a Beis medrish will also cause you to waste time from your learning and your learning won’t be as sharp since it will be fragmented.
A baal lashon hara, one who constantly is speaking lashon hara is so bad that the Chofetz Chaim warns that a Rebbe might have to expel a student if he sees he can’t stop him from speaking lashon hara, as Rav Ashi, an Amora who was one of the compilers of the gemara had to do with one of his students in Sanhedrin 31a.
If one finds himself in a group of people speaking lashon hara then he certainly should rebuke them if he thinks it will work. If it wouldn’t work but he thinks it won’t harm things then he should still rebuke them to let people know he is in disagreement of what’s happening. But if he thinks it will only harm the situation and make matters worse then it is better to say nothing. Just as praising someone is not allowed it will lead to lashon hara, so too rebuking someone for speaking lashon hara is not allowed if it will lead to worse lashon hara. It is better to try to switch the conversation or walk away. If you can’t do that then stick your finger in your ears and if that’s too embarrassing then make a face of disgust and be absolutely still, and have in mind not to accept anything that you hear.
But at all costs one should try to stop others from sinning, just like the Rambam says that if you see a rabbi in the street wearing Shaatnez then one should pull off his garment in the middle of the street to avoid a chillul Hashem. In this case it’s easier, just create a distraction or change subjects from the conversation at hand, or as preemptive measures give incentives to people for not speaking lashon hara and learning the laws about it.