I have done both in the past, even bought some machines for at home (exercise bike etc). BUT for motivation it has to be the gym. I've got to know some people in classes, the gym staff etc so I can say hello and pass the time of day etc.
I push myself harder, in a class with an instructor they push you and you respond I think.
Also I work well to 'plans' so running plans like couch to 5k, or weight lifting plans like 5x5, 5,3,1. (google if you want to know more as they're well covered).
I like goals and to meet them.