I think it depends on your preference. I worked out at the gym for many years before covid and after the pandemic I built a home gym with a power rack, barbell, adjustable dumbells, and cable machine. Biggest advantage of this is not having to share a rack with anyone. It was sometimes annoying to have to wait for equipment.
What I'll say is that I really appreciated starting at the gym as I got to have access to every machine and workout equipment. This let me build a workout plan over years and get a good idea of what sort of equipment I would need to stay active. I also found it helpful to see what other people were doing at the gym. Some people clearly have no idea what they are doing, but seeing what other experienced people at the gym were doing gave me some great ideas of what to incorporate into my workouts.
I also did have a personal trainer for 6 months and I highly recommend this, especially when you are new to working out. The biggest value is from having someone experienced give you tips and tricks on how to improve your form and workout safely. Especially as you get stronger and lift heavier weights. It's easy to lift something slightly wrong and really hurt yourself.
Overall, I always enjoyed my time at the gym and it gave me the knowledge to built a great home gym.
Lol, I like this better than the one that is supposed to inspire you to work forever and never question the purpose.