We study the longitudinal stability of beam-plasma systems in the presence of a density inhomogeneity in the background plasma. Previous works have focused on the non-relativistic regime where hydrodynamical models are used to evolve pre-existing Langmuir waves within inhomogeneous background plasmas. Here, for the first time we study the problem with kinetic equations in a fully-relativistic way. We do not assume the existence of Langmuir waves, and we focus on the rate and the mechanism by which waves are excited in such systems from an initial perturbation. We derive the structure of the unstable modes and compute an analytical approximation for their growth rates. Our computation is limited to dilute and cold beams, and shows an excellent agreement with particle-in-cell simulations performed using the SHARP code. We show that, due to such an inhomogeneity, the virulent beam-plasma instabilities in the intergalactic medium are not suppressed but their counterparts in the solar wind can be suppressed as evidenced by propagating type-III solar radio bursts.