If there are 24 people and each of them will eat 2 cups of ice cream, then there will be 48 cups of ice cream in total.
We know that 1 gallon is equivalent to 16 cups, so we form the following proportion

Let's solve for x

Hence, he should buy 3 tubs of ice cream in total.