We show a first-principles approach for analyzing anharmonic properties of lattice vibrations in solids. We firstly extract harmonic and anharmonic force constants from accurate first-principles calculations based on the density functional theory. Using the many-body perturbation theory of phonons, we then estimate the phonon scattering probability due to anharmonic phonon-phonon interactions. We show the validity of the approach by computing the lattice thermal conductivity of Si, a typical covalent semiconductor, and selected thermoelectric materials PbTe and Bi2Te3 based on the Boltzmann transport equation. We also show that the phonon lifetime and the lattice thermal conductivity of the high-temperature phase of SrTiO3 can be estimated by employing the perturbation theory on top of the solution of the self-consistent phonon equation.