How do I select a default sound card with alsa?

Find your desired card with:

cat /proc/asound/cards

and then create /etc/asound.conf with the following entries:

defaults.pcm.card 1
defaults.ctl.card 1

Replace 1 with number of your card determined above. Source: https://www.alsa-project.org/wiki/Setting_the_default_device


This is a way set default sound output card dynamically using PulseAudio (not ALSA).

  1. Check list of Sources and Sinks

    $ pactl list short sources
    0   alsa_output.pci-0000_00_1b.0.analog-stereo.monitor  module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
    1   alsa_input.pci-0000_00_1b.0.analog-stereo   module-alsa-card.c  s16le 2ch 44100Hz   SUSPENDED
    2   combined.monitor    module-combine-sink.c   s16le 2ch 44100Hz   SUSPENDED
    
    $ pactl list short sinks
    0   alsa_output.pci-0000_00_1b.0.analog-stereo  module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
    1   combined    module-combine-sink.c   s16le 2ch 44100Hz   IDLE
    2   alsa_output.pci-0000_01_00.1.hdmi-stereo    module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
    
  2. Set defaults:

    $ pactl set-default-source alsa_input.pci-0000_00_1b.0.analog-stereo
    $ pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
    

It is possible even to set ports too. See How to switch sound output with key shortcut

Reference: man pactl


Seeing as I don't have Pulse, the accepted answer isn't valid for others like me.
This should provide a decent solution here that works off of ALSA alone.

I have a bit of detail since I have 3 devices (onboard 2-channel, video card HDMI, PCI 5.1-channel) in my machine, with my preferred device being last.

what worked for me was editing /etc/asound.conf with the following:
(resource: http://www.alsa-project.org/main/index.php/Asoundrc )

pcm.!default {
    type hw
    card 0
}

ctl.!default {
    type hw
    card 0
}

If I would've intuitively set my default device as 2, the order of the above devices would've flipped to this after restarting:

0: [CMI8738        ]
1: [Nvidia         ]
2: [Nvidia_1       ]

with the default device being 2.
(this would continue after every reboot, and no restarting alsa did not make apps play audio)

To stop my machine from trolling me, I had to edit /etc/modprobe.d/alsa-base.conf and add the following line:
(resource (search for the 6th occurrence of "order"): https://alsa.opensrc.org/MultipleCards#How_to_choose_a_particular_order_for_multiple_installed_cards )

options snd slots=snd-cmipci,

which forced my preferred device at 0 so the default card would match:

Hopefully I'll never have to touch these settings again, and it'll help others like me who don't want to deal with PulseAudio dropping audio streams.
(yes this means poorly developed apps like Discord and Firefox won't identify your audio devices without Pulse)

EDIT: just to update now that I've had trouble with this issue...
if you have multiple devices sharing the same driver, the solution here is quite dirty:

options snd-hda-intel index=1,0 vid=0x####,0x#### pid=0x####,0x####

for some reason, ordering the index inversely orders the devices properly for me...

if you'd like other device drivers ordered before or after this, you can combine this with:

options snd slots=snd-cmipci,snd-hda-intel,

to obtain the vid/pid info, you use the command:

lspci -nn | grep Audio

which should list your audio devices for you with the ids in [vid:pid] at the end of each line.
(use caution if your audio device name doesn't contain "Audio")