Configuring Bluetooth on Linux
The Bluetooth Blues
ByGetting Bluetooth and PulseAudio to play nicely takes a little work. Bruce walks you through the basics of getting Bluetooth up and running on Linux.
Getting Bluetooth sound to work always reminds me of the bad old days when configuring every piece of hardware to function with Linux was a struggle. To be fair, part of the trouble is PulseAudio, Linux’s sound system, which can be a cantankerous application in its own right and does not play particularly well with Bluetooth, often ceasing to coordinate with the least change. Still another challenge is finding relevant online help. However, the stereo-quality sound of high-end Bluetooth speakers makes the struggle worth any audiophile’s time. What follows is some of the basics, most of which applies to other Bluetooth devices as well.
Before configuring Bluetooth support, update your PulseAudio installation and check that it is still working. At least in theory, this precaution can help you pinpoint where any problems lie. In addition, install or update the following packages: bluetooth, pulseaudio-module-bluetooth, and pavucontrol, the GUI for configuring PulseAudio. To check that Bluetooth support is enabled, run:
systemctl status bluetooth
You may need to reboot before your system is ready or to stop and restart Bluetooth and PulseAudio using systemctl (Figure 1). For instance, to start Bluetooth, use the command:
systemctl start bluetooth
If Bluetooth is not running, you can buy a USB dongle for $5-40, depending on quality, range, energy consumption, and version. Low energy consumption dongles may have a limited range of a couple of meters, so the positioning of your speaker may affect your purchase. Most dongles support Bluetooth 4.0, and many will support earlier versions. Most, too, should support Linux out of the shrink wrap.
Configuration
To set up a speaker, you must pair it with your computer’s Bluetooth support, linking the two. To save time, you can also set your speaker as trusted, so it pairs automatically each time it is turned on, saving you time and repetition. Depending on the software you use, your computer can be identified as the controller or adapter, while the speaker device, for some arcane reason, is sometimes referred to as a headphone.
You can use a variety of desktop tools for configuration, including the tools provided by Gnome and KDE, or install blueman. However, I recommend bluetoothctl for configuration (Figure 2), a command-line tool that breaks down tasks into smaller steps, so you can see where the problem lies (Figure 3). bluetoothctl consists of the basic command, plus a sub-command, and, in places the device or controller ID. For instance, the command
bluetoothctl select F4-F5-D8-E7-B5-AD
sets the controller to the one with that ID. You could also use a user-friendly alias, if you have given the controller one:
bluetoothctrl select Nanday
The first step is to prepare the controller. Use the sub-commands list or show to learn the controller’s ID or copy it from a desktop tool. Then use discoverable to get the speaker’s ID. To pair, consult the speaker’s manual about how to prepare it for pairing. (In the case of my speaker, that consists of holding down the plus volume control at the same time as pressing a small button by the on button. Your speaker may have another method. Usually, an audio cue tells you that the speaker is ready.) The speaker will be pairable for about two minutes. If you fail to pair the first time, one reason may be that you started the attempt to pair with too little time left to establish the connection. Pairing may also be erratic for other reasons, so you may need several tries before you are successful.
Returning to the speaker, use the sub-command pairable on, quickly followed by pair SPEAKER-ID. When a pairing is successful, another audio cue is given, but use paired devices to check. Finish with trust SPEAKER-ID so that the speaker is automatically paired when turned on, and your speaker is ready for use. You will want your speaker to be trusted, because, unlike wired speakers, your Bluetooth speaker runs on batteries, and you probably do not want to have it on all the time. As a last step for security’s sake, run discoverable off so your controller does not become a back door to your entire system.
At this point, open pavucontrol and go to the Configuration tab (Figure 4). The tab should show your speaker, but sometimes it will not be turned on. The most likely setting you need will be High Fidelity Playback (A2DP Sink), which gives the highest quality sound. Should you have trouble with a particular application, start it and find it on pavucontrol’s Playblack tab (Figure 5). From here, you can adjust volume, set the output to your Bluetooth speaker, or reset the volume.
In KDE’s Plasma, you can also use Phonon to choose which output source to use for which purpose, such as for video games or accessibility, in case that matters to your purposes. Phonon has been de-emphasized in recent Plasma releases. If you have only the one speaker, it will be listed as simply PulseAudio Sound Speaker. Still, check that it has been applied to all the categories you need -- you might get a burst of sound from a few clicks (Figure 6).
The processes of pairing and setting a device to trusted are simplest when the speaker is the only Bluetooth device. In some cases, you may want to use the block or unconnect sub-command to temporarily conceal another Bluetooth device to avoid confusion, restoring it later with unblock or connect. You might also use these sub-commands along with untrust when a Bluetooth device reaches the end of its usefulness.
Advanced Troubleshooting
Unfortunately, both Bluetooth and PulseAudio are erratic enough that the process is not always straightforward. It is all too common that a system that has been working perfectly before it stops working for no obvious reason. The problem can be as simple as PulseAudio not turning on a perfectly installed speaker, which can be quickly fixed in pavucontrol. Or perhaps a file in ~./.config/pulse, left there after a previous installation, is not compatible with an upgrade or the files in /etc/pulse. If editing or deleting some of these files does nothing, a host of other solutions are identified on the Debian and Arch Bluetooth wikis.
Sometimes, coaxing Bluetooth and PulseAudio to get along can make me wonder if the effort is worth my time. However, music to work by matters to me. When I find myself in the middle of yet another temporary breakdown of sound for no apparent reason, I remind myself that two decades ago, similar problems frequently happened with printers, scanners, and even keyboards and mouses. Surely there’s a less painful means to stay in touch with my Linux roots.
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.