How can I change the default audio device from command line?
Ubuntu’s desktop gui is great for changing audio settings (System->Preferences->Sound), like the default input/output device and setting the volume.
However, I would like to be able to do these things from the command-line. What tool is the gui using behind the scenes?
Yes there is type alsamixer in terminal
F1 – Help
F2 – System Information
F6 – Select Sound Card
Esc – Exit the menu
You can control PulseAudio thoroughly through the command line using
pactl commands. For options see
pacmd --help or the wiki at PulseAudio:
pacmd list-sinks for name or index number of possible sinks
pacmd list-sources for name or index number of possible sources
pacmd set-default-sink "SINKNAME" | index to set the default output sink
pacmd set-default-source "SOURCENAME" | index to set the default input
pacmd set-sink-volume index volume
pacmd set-source-volume index volume for volume control (
65536 = 100 %,
0 = mute; or a bit more intuitive
0x10000 = 100 %,
0x7500 = 75 %,
0x0 = 0 %)
and many many more CLI options.
Note: Changing the output sink through the command line interface can only take effect if stream target device reading is disabled. This can be done by editing the corresponding line in
load-module module-stream-restore restore_device=false
Restart PulseAudio for changes to take effect:
For a more elaborate tutorial on how to do this, and for instructions on how to change the sink during playback see this answer.
Not the actual Ubuntu volume control, but better! It lets you control default devices, and even devices per application/stream.
You have to have the app actually be recording/playing for it to appear in the ‘Playback’ or ‘Recording’ tabs, but once you choose the device for that app, it seems to remember it forever.
Also, (on a side note), for old (non pulse) applications, run them after
I found these instructions to be clear and easy to follow. It explains how to set the default audio output device (speakers, etc), from the command line, as well as how to make your chosen setting the system default, so that it is set after the machine is rebooted.
Set the default output sink
To list the output sinks available, type the following command:
$ pacmd list-sinks | grep -e ‘name:’ -e ‘index:’
The * in front of the index indicates the current default output.
To set a system wide default, add the source name in the default.pa file:
When done then you can logout/login or restart PulseAudio manually for these changes to take effect.
In the case of WirePlumber (a PipeWire session manager),
wpctl can help you.
Get the available audio devices with
wpctl status (default is shown with a
PipeWire 'pipewire-0' [0.3.77, machitgarha@machitgarha, cookie:2827478639] └─ Clients: ... Audio ├─ Devices: │ 46. Built-in Audio [alsa] │ 78. Headset H390 [alsa] │ ├─ Sinks: │ * 49. Built-in Audio Analog Stereo [vol: 0.90] │ 84. Headset H390 Pro [vol: 1.00] │ ├─ Sink endpoints: │ ├─ Sources: │... ...
Extract the number of the device from the "Sinks" section, and change the default audio sink (i.e. device) using
wpctl set-default. For example, to change it to "Headset H390 Pro":
wpctl set-default 84
Check if the default sink is changed with