You can use amixer. It's in the
alsa-utils package on Ubuntu and Debian.
amixer without parameters to get an overview about your controls for the default device.
You can also use
alsamixer without parameters (from the same package) to get a more visual overview. Use F6 to see and switch between devices. Commonly you might have PulseAudio and a hardware soundcard to select from.
amixer with the
set command to set the volume.
For example, to set the master channel to 50%:
amixer set Master 50%
Master is the control name and should match one that you see when running without paramters.
% sign, without it it will treat the value as 0 - 65536 level.
If PulseAudio is not your default device, you might can use the
amixer -D pulse set Master 50%
Other useful commands pointed out in the comments:
To increase/decrease the volume use
+/- after the number, use
amixer set Master 10%+
amixer set Master 10%-
To mute, unmute or toggle between muted/unmuted state, use
amixer set Master mute
amixer set Master unmute
amixer set Master toggle
Also note that there might be two different percentage scales, the default raw and for some devices a more natural scale based on decibel, which is also used by
-M to use the latter.
Finally, if you're interested in PulseAudio only, you might want to check out
pactl (see one of the other answers).