You can use amixer. It's in the alsa-utils package on Ubuntu and Debian.

Run 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.

Then use 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.

Note the % sign, without it it will treat the value as 0 - 65536 level.

If PulseAudio is not your default device, you might can use the -D switch:

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 alsamixer . Use -M to use the latter.