Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active May 3, 2025 15:21
Show Gist options
  • Save plembo/073587b2f8ed4e563e85684fe9b6039b to your computer and use it in GitHub Desktop.
Save plembo/073587b2f8ed4e563e85684fe9b6039b to your computer and use it in GitHub Desktop.
Set the default audio device(s) in Ubuntu 18.04 LTS

Setting the default audio device in Ubuntu 18.04 LTS

The problem: When you log in, Gnome picks whatever it damn pleases to make the active audio device(s). In my situation this was a little used but electrically problematic (bad grounding caused it to introduce an annoying hum) Dell Sound Bar. I fiddled with the gui interfaces (both Gnome's built-in and the add-on pavucontrol), with no success.

NOTE: No longer using this as I've moved on to Ubuntu 22.04 with pipewire. I'm back to working with pavucontrol to try keeping things under control.

Some brief notes to bring together what I've personally found to work.

The definitive thread on askubuntu is here:

https://askubuntu.com/questions/1038490/how-do-you-set-a-default-audio-output-device-in-ubuntu-18-04

This contains the answer(s), but in a disjointed way.

Here's what worked for me:

  1. Get the names of your audio devices loading by running pactl list short sinks (for me this would include alsa_output.pci-0000_00_1f.3.analog-stereo, my built-in audio).
  2. Create a new command with Startup Applications called "Set Default Audio Output" and enter this as the Command: pactl set-default-sink <device name>. In my case:
pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo
  1. Save and exit Startup Applications and log out.
  2. Log back in and verify that your desired audio device is now active (Gnome settings sound applet or pavucontrol will show this).

While normally I'd prefer to run something like this from .bashrc or .profile, I opted for a Startup Applications command because it launches with Gnome, and so won't get bigfooted by whatever settings the damned gui decides to impose.

As I was going through this exercise, I couldn't help but think I'd been through this kind of struggle with an operating environment before. Then I remembered. Right. Windows 95 (and every Windows since).

NOTE: The favoritism shown by PulseAudio to USB audio devices is no mystery. That's driven, among other things, by line 37 in the default /etc/pulse/default.pa (the whole section in context):

 35 ### Use hot-plugged devices like Bluetooth or USB automatically (LP: #1702794)
 36 .ifexists module-switch-on-connect.so
 37 load-module module-switch-on-connect
 38 .endif

Anyone trying to control Pulse's behavior at the system, rather than user, level should comment that line out. For user level fixes like the one above it can be left in place (which is a relief because changes there could be overwritten by future updates).

NOTE: If you're thinking about doing PCI passthrough with an Intel CPU having onboard graphics (e.g. HD530 on a 6th generation i5 or i7) you'll most likely have to blacklist the i915 module. Doing that may also make the onboard audio inaccessible on boot, mooting the above trick. You'll probably be able to switch to onboard audio after logging in, but that might compromise your ability to passthrough GPU. As always, YMMV. The results I observered were on a 3 year-old i5-6500 in an Asus PRIME B250M-C/CSM. And no, I ultimately wasn't able to get passthrough to work for... reasons.

@plembo
Copy link
Author

plembo commented Oct 10, 2021

Re prioritizing internal mic over 3.5 mm earphone mic. You may not be able to. On my X250 laptop, plugging earbuds with a built-in mic into the 3.5 mm jack automatically shuts off the internal mic. It seems that behavior is baked into the hardware. Since the internal mic for the X250 is more horrible sounding than a typical cheap earbud mic, I now use a tiny external usb sound card (https://amzn.to/3BH2N7K) between an earbud mic and the computer. The sound is noticeably better (probably because noise reduction actually works now). This wiki article is about the best out there on configuring PulseAudio, so you may want to look at it: "PulseAudio". ArchLinux Wiki. https://wiki.archlinux.org/title/PulseAudio, and the companion article on "Troubleshooting", https://wiki.archlinux.org/title/PulseAudio/Troubleshooting. Also take a look at your computer hardware manual and any forums specific to that hardware.

@alidplus2
Copy link

+1

@izam-mohammed
Copy link

Failure: No such entity is the result :(

@plembo
Copy link
Author

plembo commented Sep 21, 2022

Curious to know what the result of running pactl list short sinks on your system was and if you substituted what it showed for my example device? I'm moved on to Ubuntu 22.04, which uses pipewire under the covers, so I don't use this method any more. I've been reduced to using pavucontrol to simply shut everything down except for my audio interface (which shows up as alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo-output). We'll see how long that holds.

@snalawad
Copy link

Also, please tell how to undo this in case I have to under a different circumstance.

@plembo
Copy link
Author

plembo commented Oct 22, 2022

On undoing: as I mention above, this method stopped working for me when I upgraded to 22.04 (which uses pipewire). As a result I deleted the "Set Default Audio Output" custom command from Startup Applications. If I were still on 18.04 I'd do that, as well as un-comment line 37 in etc/pulse/default.pa (that was replaced on my system during the upgrade). Since this is a Gnome desktop environment we're talking about, a reboot after those changes would probably be in order. BTW, pipewire setup with pavucontrol on 22.04 seems to work pretty well, although I now completely disable that old Dell Sound Bar in pavucontrol and only re-enabling it when needed (note Gnome's own volume control is completely useless for anything more than controlling volume).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment