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
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.