We herein present a first-principles formulation of the Green-Kubo method that allows the accurate assessment of the non-radiative thermal conductivity of solid semiconductors and insulators in equilibrium ab initio molecular dynamics calculations. Using the virial for the nuclei, we propose a unique ab initio definition of the heat flux. Accurate size- and time convergence are achieved within moderate computational effort by a robust, asymptotically exact extrapolation scheme. We demonstrate the capabilities of the technique by investigating the thermal conductivity of extreme high and low heat conducting materials, namely diamond Si and tetragonal ZrO$_2$.