We show that the Raman frequency associated with the vibrational mode at ~1,580 cm-1 (the G mode) in both metallic and semiconducting carbon nanotubes shifts in response to changes in the charge density induced by an external gate field. These changes in the Raman spectra provide us with a powerful tool for probing local doping in carbon nanotubes in electronic device structures, or charge carrier densities induced by environmental interactions, on a length scale determined by the light diffraction limit. The G mode shifts to higher frequency and narrows in linewidth in metallic carbon nanotubes at large fields. This behaviour is analogous to that observed recently in graphene. In semiconducting carbon nanotubes, on the other hand, induced changes in the charge density only shift the phonon frequency, but do not affect its linewidth. These spectral changes are quantitatively explained by a model that involves the renormalization of the carbon nanotube phonon energy by the electron-phonon interaction as the carrier density in the carbon nanotube is changed.