  We study the gravitational instability of a general relativistic complex
scalar field with a quartic self-interaction in an infinite homogeneous static
background. This quantum relativistic Jeans problem provides a simplified
framework to study the formation of the large-scale structures of the Universe
in the case where dark matter is made of a scalar field. The scalar field may
represent the wave function of a relativistic self-gravitating Bose-Einstein
condensate. Exact analytical expressions for the dispersion relation and Jeans
length $\lambda_J$ are obtained from a hydrodynamical representation of the
Klein-Gordon-Einstein equations. When relativistic effects are fully accounted
for, we find that the perturbations are stabilized at very large scales of the
order of the Hubble length $\lambda_H$. Numerical applications are made for
ultralight bosons without self-interaction (fuzzy dark matter), for bosons with
a repulsive self-interaction, and for bosons with an attractive
self-interaction (QCD axions and ultralight axions). We show that the Jeans
instability is inhibited in the ultrarelativistic regime (early Universe and
radiationlike era) because the Jeans length is of the order of the Hubble
length ($\lambda_J\sim\lambda_H$), except when the self-interaction of the
bosons is attractive. By contrast, structure formation can take place in the
nonrelativistic regime (matterlike era) for $\lambda_J\le \lambda\le
\lambda_H$. Since the scalar field has a nonzero Jeans length due to its
quantum nature (Heisenberg uncertainty principle or quantum pressure due to the
self-interaction of the bosons), it appears that the wave properties of the
scalar field can stabilize gravitational collapse at small scales, providing
halo cores and suppressing small-scale linear power. This may solve the CDM
crisis such as the cusp problem and the missing satellite problem.
