I believe you don't really have to go to the gym. If your goal is to lose weight, the first thing to do is check your diet. And then just do some regular body weight exercises at home and go for a run a few times per week.
That's all it takes.
Gyms are for people who are into body building. For someone who wants to just get fitter or lose weight, there is no need to go to a gym, you can get fit at home.
I started with this website called HASFit and then did this 500 reps challenge for 14 days straight.
It totally changed my body and fitness.
Ofcourse this is my personal opinion and experience. ✨
I agree that it isn't mandatory, @hardikv. But for a lot of people, I do understand that it gives their fitness attempts some structure. I know that a lot of people (beginners, especially) don't really know what to do on their own, be it home workouts, or even just what activities would help their goals. I'm personally a big fan of home workouts, even though I do participate in group classes (not gyms). That said, different strokes for different folks, eh? :)