There are literally dozens of ways to do this. Here are four, in order of increasing complexity, sophistication, and cost:
Shaft with a keyway, dog point set screw(s)in gear
Shaft with a key in a keyway (key attached with screws)
Splined shaft, splined hole in gear (many types of spline)
Polygon shaft, polygon hole in gear
You might also consider fixing the gear to the shaft and sliding the shaft in the support bearings instead.