  By allowing gauge anomaly cancellation between fermions in different families
we find a non-universal solution for a $Z'$ family of models with the same
content of fermions of the standard model plus three right-handed neutrinos. We
also impose constraints from the Yukawa interaction terms in such a way that at
the end we obtain a solution with six free parameters. Our solution contains as
particular cases well-known models in the literature. As an application, we
report a model that evades LHC constraints, flavor changing neutral currents
and low energy constraints. Simultaneously, the model is able to explain the
flavor anomalies in the Wilson coefficients $C_9(\mu)$ and $C_{10}(\mu)$
without modifying the corresponding Wilson coefficients for the first family.
In our approach, this procedure is always possible for $Z'$ masses smaller than
$\sim 2.5$~TeV.
