The differential virial theorem (DVT) is an explicit relation between the electron density ρ(r), the external potential, kinetic energy density tensor, and (for interacting electrons) the pair function. The time-dependent generalization of this relation also involves the paramagnetic current density. We present a detailed unified derivation of all known variants of the DVT starting from a modified equation of motion for the current density. To emphasize the practical significance of the theorem for noninteracting electrons, we cast it in a form best suited for recovering the Kohn–Sham effective potential vs(r) from a given electron density. The resulting expression contains only ρ(r), vs(r), kinetic energy density, and a new orbital-dependent ingredient containing only occupied Kohn–Sham orbitals. Other possible applications of the theorem are also briefly discussed. © 2012 Wiley Periodicals, Inc.