We study the statistical mechanics of a one-dimensional log gas or β-ensemble with general potential and arbitrary β, the inverse of temperature, according to the method we introduced for two-dimensional Coulomb gases in Sandier and Serfaty (Ann Probab, 2014). Such ensembles correspond to random matrix models in some particular cases. The formal limit β = ∞ corresponds to "weighted Fekete sets" and is also treated. We introduce a one-dimensional version of the "renormalized energy" of Sandier and Serfaty (Commun Math Phys 313(3):635-743, 2012), measuring the total logarithmic interaction of an infinite set of points on the real line in a uniform neutralizing background. We show that this energy is minimized when the points are on a lattice. By a suitable splitting of the Hamiltonian we connect the full statistical mechanics problem to this renormalized energy W , and this allows us to obtain new results on the distribution of the points at the microscopic scale: in