We report the results of epitaxial growth experiments on AlxGa1−xN (0≤ x ≤ 1) on Si(111) and sapphire substrates aimed at understanding the origin and elimination of cracking. We describe growth procedures resulting in thick layers of AlxGa1−xN, grown by gas source molecular beam epitaxy with ammonia, that are free of cracks. In GaN layers with the thickness of ∼2.5 µm, we find the background electron concentration of (1-2)×1016 cm−3 and mobility of (800±100) cm2/Vs. In AlxGa1−xN (0.2 < x < 0.6) with the film thickness of 0.5-0.7 µm the electron concentration of (2-3)×1016 cm−3 is obtained. Low background concentrations in GaN allow for formation of p-n junctions by doping with Mg. Light emitting diodes with the peak emission at 380 nm have been demonstrated.