Connecting Bluetooth headphones using the command line in Debian involves several steps. Below are the instructions to help you set up everything:
-
Install Required Packages:
bluetooth: Provides the Bluetooth protocol stack.
bluez: Contains utilities for the Bluetooth stack.
bluez-tools: Offers command-line tools for managing Bluetooth devices.
pulseaudio-module-bluetooth: Enables PulseAudio support for Bluetooth audio devices.
You can install these packages by running:
sudo apt update
sudo apt install bluetooth bluez bluez-tools pulseaudio-module-bluetooth
-
Start and Enable Bluetooth Service:
- Ensure that the Bluetooth service is started and enable it to start on boot:
sudo systemctl start bluetooth
sudo systemctl enable bluetooth
-
Using bluetoothctl to Manage Bluetooth Devices:
- Launch
bluetoothctl which is an interactive command line tool for configuring Bluetooth devices.
bluetoothctl
-
Pair Your Bluetooth Headphones:
-
Once in bluetoothctl, follow these steps to pair your headphones:
- Turn on the agent for simple pairing (this helps manage pair requests):
agent on
- Enable scanning for Bluetooth devices:
scan on
-
Make sure your headphones are in pairing mode. After a few moments, you should see your headphones listed by their MAC address (e.g., xx:xx:xx:xx:xx:xx). Take note of this address.
-
Pair with your headphones:
pair <MAC>
- After successful pairing, you need to connect to the headphones:
connect <MAC>
Where <MAC> is the MAC address of your Bluetooth headphones.
- Mark the headphones as trusted so they can connect automatically in the future:
trust <MAC>
- Disable scanning once you have paired your device to avoid unnecessary resource usage:
scan off
-
Configuring PulseAudio:
- If PulseAudio is running, it should recognize the connected Bluetooth headphones automatically. You can check if the module is loaded using:
pactl list | grep bluetooth
- If it's not loaded, you can load it manually:
pactl load-module module-bluetooth-discover
- You might also need to set the headphones as the default sink (audio output device):
pacmd set-default-sink <name_of_bluez_sink>
To find the exact sink name, you can list all available sinks:
pacmd list-sinks
-
Playing Audio:
- Now you can test to make sure audio is working. Play some audio using a command-line tool like
aplay to send an audio file to the default sink.
aplay /path/to/audio/file.wav
Example Workflow
Here's an example simplified workflow:
sudo apt update
sudo apt install bluetooth bluez bluez-tools pulseaudio-module-bluetooth
sudo systemctl start bluetooth
sudo systemctl enable bluetooth
bluetoothctl
In bluetoothctl:
agent on
scan on
# (wait for your device to appear, then note its MAC address)
pair xx:xx:xx:xx:xx:xx
connect xx:xx:xx:xx:xx:xx
trust xx:xx:xx:xx:xx:xx
scan off
Back in the shell:
pactl load-module module-bluetooth-discover
pacmd set-default-sink <name_of_bluez_sink>
By following these steps, you should be able to pair and use your Bluetooth headphones with Debian via the command line.