The properties of GaN, grown on sapphire by molecular-beam epitaxy, have been investigated with respect to the properties of the underlying AlN nucleation layer. We show that the AlN thickness and the Al/N flux ratio have pronounced effects on the surface morphology and crystal quality of the GaN overlayer. Low Al/N ratio (≪0.4) leads to N-polarity GaN with poor crystal quality. For ratios between 0.4 and 0.7 the surface is smooth with Ga polarity. Higher Al/N flux ratios result in Ga-polar surfaces having plateaus intersected by holes. Optimum values for the GaN(0002) ω scan (full width at half maximum of 250 arc sec) and the surface roughness (root mean square of 0.7 nm) were found for a 3-nm-thick AlN nucleation layer (Al/N ratio of 0.6).