sperea.es
Published on

How to get bluetooth headphones to work with Ubuntu

Authors

Managing bluetooth sound devices in Ubuntu can sometimes be a bit cumbersome (in my case I have Sony WH1000MX4 in the office and Bose QuietComfort 45 at home), especially if you are not familiar with the terminal or the intricacies of Linux. However, with the right tools and knowledge, it becomes quite simple. In this article, we will explore how to configure and manage Bluetooth in Ubuntu using the built-in options as well as Blueman's Bluetooth Manager.

Pre-requisites

Before diving into the process, make sure you have:

  • Ubuntu Installed and Running
  • Active Internet Connection
  • Sudo Privileges
  • Inbuilt or External Bluetooth Adapter

If you're unsure about which Bluetooth adapter to use with Linux, check out our previous post about Linux-compatible Bluetooth adapters.

Enabling Bluetooth Service

Ubuntu and many other Linux distributions typically come with Bluetooth pre-configured. To confirm if Bluetooth is running on your system, execute the following command:


sudo systemctl status bluetooth.service

If the service is active, you can proceed to the next steps. Otherwise, use the following commands to enable Bluetooth:

  • For using a Bluetooth dongle, run:

modprobe btusb

  • To start the Bluetooth service:

sudo systemctl start bluetooth.service

  • To enable it on boot:

sudo systemctl enable bluetooth.service

Finally, recheck the status using sudo systemctl status bluetooth.service to ensure it's running.

Problem 1: Headphone does not pair or is refusing to connect with bluetooth / pulseaudio

Setting up BlueZ

Before you can manage your Bluetooth devices efficiently, you'll need to install BlueZ, the official Bluetooth stack for Linux. This software provides the necessary support for core Bluetooth layers and protocols.

First, update your repositories:


sudo apt update

Then install BlueZ and its utilities:


sudo apt install bluez bluez-tools

With BlueZ set up, you can now proceed to install Blueman.

Installing Blueman

Blueman is an intuitive Bluetooth Manager that comes with a graphical interface. It offers functionalities like:

  • Network connection via dial-up
  • Audio device connection
  • File transfer via OBEX
  • Device pairing
  • Input device connection
  • Bluetooth network creation

Via Ubuntu Software Center

  1. Launch the Ubuntu Software Center.
  2. Search for "Blueman" and click on "Blueman Bluetooth Manager."
  3. Click 'Install' and provide the necessary authentication.
  4. Once installed, it can be started from the applications menu.

Via Terminal

Alternatively, you can also install Blueman through the terminal. Execute the following command:


sudo apt install blueman

After the installation, run Blueman by typing:


blueman-manager

Note: Ensure that your Bluetooth adapter is connected before running this command.

Connecting Bluetooth Devices

Connecting to devices using Blueman is a breeze. Open Blueman, make sure your desired devices are discoverable and within range. You should be able to see them in the Blueman dashboard, where you can initiate the connection.

Problem 2: Headphones connect but ubuntu doesn't detect them as a sound device and I can't use them

Workaround: Adjust PulseAudio Configuration

To solve this problem, we will need to edit some PulseAudio configuration files. Here's how to do it:

Step 1: Edit the default.pa File

  1. Open your terminal and type the following command to edit the file:

    sudo nano /etc/pulse/default.pa

  1. Locate the following line:

    load-module module-bluetooth-discover

  1. Comment it out by adding a # at the beginning of the line. It should look like this:

    #load-module module-bluetooth-discover

  1. Save the changes and close the editor.

Step 2: Edit the start-pulseaudio-x11 File

  1. In the terminal, run the following command:

    sudo nano /usr/bin/start-pulseaudio-x11

  1. Find the snippet of code that looks like this:

    if [ x"$SESSION_MANAGER" != x ] ; then     /usr/bin/pactl load-module module-x11-xsmp “display=$DISPLAY session_manager=$SESSION_MANAGER> /dev/null fi

  1. Add the following line right after that snippet:

    /usr/bin/pactl load-module module-bluetooth-discover

  1. Save the changes and close the editor.

Step 3: Restart PulseAudio and Test

Now, it's advisable to restart the PulseAudio service to apply the changes. Execute the following command in the terminal:


pulseaudio -k && pulseaudio --start

Test your Bluetooth headphones to ensure that they now function correctly.