The phase diagrams and phase transitions of bosons with short-ranged repulsive interactions moving in periodic and/or random external potentials at zero temperature are investigated with emphasis on the superfluid-insulator transition induced by varying a parameter such as the density. Bosons in periodic potentials (e.g., on a lattice) at T=0 exhibit two types of phases: a superfluid phase and Mott insulating phases characterized by integer (or commensurate) boson densities, by the existence of a gap for particle-hole excitations, and by zero compressibility. Generically, the superfluid onset transition in d dimensions from a Mott insulator to superfluidity is ideal, or mean field in character, but at special multicritical points with particle-hole symmetry it is in the universality class of the (d+1)-dimensional XY model. In the presence of disorder, a third, Bose glass phase exists. This phase is insulating because of the localization effects of the randomness and analogous to the Fermi glass phase of interacting fermions in a strongly disordered potential. The Bose glass phase is characterized by a finite compressibility, no gap, but an infinite superfluid susceptibility. In the presence of disorder the transition to superfluidity is argued to occur only from the Bose glass phase, and never directly from the Mott insulator. This zero-temperature superfluid-insulator transition is studied via generalizations of the Josephson scaling relation for the superfluid density at the ordinary transition, highlighting the crucial role of quantum fluctuations. The transition is found to have a dynamic critical exponent z exactly equal to d and correlation length and order-parameter correlation exponents and which satisfy the bounds 2/d and 2-d, respectively. It is argued that the superfluid-insulator transition in the presence of disorder may have an upper critical dimension dc which is infinite, but a perturbative renormalization-group calculation wherein the critical exponents have mean-field values for weak disorder above d=4 is also discussed. Many of these conclusions are verified by explicit calculations on a model of one-dimensional bosons in the presence of both random and periodic potentials. The general results are applied to experiments on He4 absorbed in porous media such as Vycor. Some measurable properties of the superfluid onset are predicted exactly [e.g., the exponent x relating the transition temperature to the zero-temperature superfluid density is found to be d/2(d-1)], while stringent bounds are placed on others. Analysis of preliminary data is consistent with these predictions. © 1989 The American Physical Society.