How do you set a default audio output device in Ubuntu 18.04?

EDIT (05/03/2020):
It seems that @phanky5 figured out a simpler solution. Please check it before you try this one.


Here is a well explained tutorial to set a default audio input/output.

First: List the audio output devices using

pactl list short sources  

Example of the output:

pactl list short sources
0   alsa_output.pci-0000_02_00.1.hdmi-stereo.monitor    module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
1   alsa_input.usb-AVerMedia_Technologies__Inc._Live_Gamer_Portable_2_5202050100060-03.analog-stereo    module-alsa-card.c  
2   alsa_output.usb-Blue_Microphones_Yeti_Stereo_Microphone_REV8-00.analog-stereo.monitor   module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
3   alsa_input.usb-Blue_Microphones_Yeti_Stereo_Microphone_REV8-00.analog-stereo    module-alsa-card.c  s16le 2ch 44100Hz   RUNNING

Second: To set a default output device run the command

pactl set-default-sink <'output_device_name'>

Example: pactl set-default-sink 'alsa_output.pci-0000_00_1f.3.analog-stereo'

Now, to make this work at every restart, follow this :

First, open the file /etc/pulse/default.pa using :

sudo -H gedit /etc/pulse/default.pa

Then scroll to the bottom of the file, where two lines starting with set- will be commented out.

Now, uncomment these lines and replace the words input and output with the number of the sink (for output) / source (for input) that you want to be the default.

Example (sets both default input and output):

### Make some devices default
set-default-sink 3
set-default-source 3

PS: As discussed in the comments with Bim, it is also possible (according to him) to put the input/output name in /etc/pulse/default.pa instead of the input/output number.

Example:

### Make some devices default
set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo
set-default-source alsa_output.pci-0000_00_1f.3.analog-stereo.monitor

After doing this, save and exit. Then, delete the ~/.config/pulse directory by running rm -r ~/.config/pulse, and then reboot the system. Once the system reboots, the appropriate devices should now be set as the defaults.



EDIT:
As mentioned by ahmorris in his answer, some had to comment this line load-module module-switch-on-connect in the file /etc/pulse/default.pa to be # load-module module-switch-on-connect in order to make the changes persistent.


Simple fix in 19.10 that worked for me:

I couldn't get the solution @singrium proposed to persist on Ubuntu 19.10. It worked with device numbers in /etc/pulse/default.pa but as I connected for example my headset device numbers were changing and things stopped working. It didn't work with device names in /etc/pulse/default.pa.

The simple workaround I found is adding the pactl set default sink command in startup applications.

  1. Run: pactl list short sinks
  2. Note the device name you want to use as default
  3. Try to run: pactl set-default-sink <Your_Device_Name>
    This should work without giving you an error message.
  4. Open the application "Startup Applications" (Should be preinstalled on Ubuntu)
  5. Click on "Add"
  6. Give your startup item a name
  7. Copy your command from above into the command field:
    pactl set-default-sink 'Your-Device-Name'
  8. Click on "Save".

You are now good to go. Your default audio device will be set on each boot and as such be persistent. If you want to change the default device simply edit the device name in startup applications command.


To make Singrium's answer work, I had to comment out this line from my /etc/pulse/default.pa by adding the #:

# load-module module-switch-on-connect

Otherwise, on startup my audio device would be set to my default device, but then would switch to my USB hub once it was detected. This prevents that switch and ensures your chosen audio device is the output.

Tags:

Sound