We'll start with the gym, this is generally perceived as the best option. It has the most equipment, including many more weights and machines than someone would most likely buy for home use. However it also has some downsides. It can be very intimidating to a beginner, especially the free weights section, as it feels like people will judge you or laugh at you for not going hard enough or not lifting heavy weights. This can increase the risk of injury greatly and may discourage you from coming back again. Although it has the best equipment, you also have to share it with other people, so it can be hard to stick to the workout you want to do if the gym is busy, or even get to do any of the exercises you wanted to at all. Furthermore, gyms can be far away which is often an inconvenience and membership is often expensive, which can put people off massively.
On the other hand, home gyms are convenient, they have no closing time, and you have all the equipment to yourself (assuming you have any). There are masses of exercises you can do with just your bodyweight, which are great for fitness, toning, beginners and recovery. If you want to, you can buy some equipment, such as dumbbells, a portable pull up bar, a barbell, etc for about the same price as a month or two's gym membership. Home workouts, therefore, would suit the student, or busy lifestyle that wouldn't be able to travel to the gym. However, this means that you are limited in the muscle gains you can make (if this is your target), as you would have to buy new weights every time you wanted to progress, for most this would probably be a happy compromise for the amount of money saved, just because you won't be a body builder doesn't mean you can't get in killer shape from home (plus you can watch tv, films etc. in your lounge whilst working out). I have heard of gamers that are trying to get in shape doing short workouts in between games or even doing as many press-ups as they can between the time they die and respawn.
However, going to the gym and working out at home do not need to be mutually exclusive. It would be a very smart idea to get a gym membership and then have a couple of dumbbells and an exercise mat at home for those days when you can't make it to the gym, or just to supplement your gym routine.
If you are going to get a gym membership, then you should go 2 or more times a week, in order to get decent value out of your membership. This doesn't mean that you have to go and do weights or hit the treadmill all the time, there are often lots of other facilities (pools, courts, sports halls etc) that you can also utilise, and therefore get better value for your money.
You can't go far wrong with either, if you're a total novice then try a few exercises at home so that you know what you're doing and what your body is capable of before joining the gym. If you're after massive muscle gains then the gym is probably the best bet, but you can still gain muscle and get in shape for a lot less money at home.
What I'm trying to say is that, everyone has specific goals, and specific circumstances. If you don't want to or can't join a gym, don't. Just be sure to make sure you workout at home. Try to figure out which is best for you, whether it's home, the gym or a blend of both.