前提と注意事項
この記事では以下を前提としています。
- 動作確認に使った Ubuntu のバージョンは 22.04 です。
- 記事投稿時点の最新版である BlueZ 5.66 をインストールします。
- BlueZ のコマンドの使い方については記載していません。
この記事のゴール
Ubuntu に 最新版の BlueZ をインストールし、以下のようにバージョンを確認できるところまでをゴールとします。
$ bluetoothctl -v
bluetoothctl: 5.66この記事の手順は以下のサイトの手順を参考にしました。
How to Install the Latest Version of BlueZ on Ubuntu
Ubuntu, by default, does not feature the latest version of a lot of software. One such software is BlueZ, an open-source Bluetooth protocol stack. Ubuntu ships with a stable yet, outdated version of BlueZ. This is done to ensure that although the software version is outdated, its well-tested and free from security flaws. However, the stability comes at the cost of missing out on new features.
makeuseof.com
事前準備
最新の BlueZ をインストールする事前準備として、以下のパッケージを Ubuntu にインストールしておきます。以下を実行します。
$ sudo apt update
$ sudo apt install build-essential libreadline-dev libical-dev libdbus-1-dev libudev-dev libglib2.0-dev python3-docutils以上で必要なパッケージのインストールが完了です。
BlueZ をダウンロードして展開する
以下を実行して 最新版の BlueZ をダウンロードして展開します。
$ wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.66.tar.xz
$ tar xvJf bluez-5.66.tar.xz
$ cd bluez-5.66
$ ./configureBlueZ をビルドする
展開するとbluez-5.66というディレクトリが作成されているはずなので、そのディレクトリに移動してconfigureを実行します。
$ cd bluez-5.66
$ ./configure以下が実行結果です。環境にもよりますが、Raspberry Pi 4 上の Ubuntu で実行すると5分ほどで完了しました。
$ ./configure
 
# 省略
 
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/bluetoothd.rst
config.status: creating lib/bluez.pc
config.status: creating mesh/bluetooth-meshd.rst
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commandsrequired エラーが発生する場合
もし./configure実行時に以下のようなerror: GLib >= 2.28 is requiredというエラーが発生する場合は、本記事の冒頭に記載した事前準備にてインストールしたパッケージが不足している可能性があります。エラーが発生した場合は、エラーメッセージに従って必要なパッケージをインストールしてから再度./configureを実行してください。
 
checking for signalfd... yes
checking for clock_gettime in -lrt... yes
checking for pthread_create in -lpthread... yes
checking for dlopen in -ldl... yes
checking for linux/types.h... yes
checking for linux/if_alg.h... yes
checking for linux/uinput.h... yes
checking for linux/uhid.h... yes
checking for sys/random.h... yes
checking for glib-2.0 >= 2.28... no
configure: error: GLib >= 2.28 is required上記の場合はおそらくlibglib2.0-devがインストールできていないことが原因になります。
BlueZ をインストールする
続いてbluez-5.66ディレクトリでmakeとmake installを実行してインストールします。
$ make
$ sudo make install以下がmakeの実行結果です。
$ make
 
# 省略
 
  CC       obexd/client/obexd-driver.o
  CCLD     obexd/src/obexd
  GEN      src/bluetoothd.8
  GEN      monitor/btmon.1
  GEN      tools/rctest.1
  GEN      tools/l2ping.1
  GEN      tools/btattach.1
  GEN      tools/isotest.1
  GEN      obexd/src/obex.service以下がmake installの実行結果です。
$ sudo make install
 
# 省略
 
libtool: install: /usr/bin/install -c profiles/cups/bluetooth /usr/local/lib/cups/backend/bluetooth
 /usr/bin/mkdir -p '/etc/dbus-1/system.d'
 /usr/bin/install -c -m 644 src/bluetooth.conf '/etc/dbus-1/system.d'
 /usr/bin/mkdir -p '/usr/share/dbus-1/services'
 /usr/bin/install -c -m 644 obexd/src/org.bluez.obex.service '/usr/share/dbus-1/services'
 /usr/bin/mkdir -p '/usr/share/dbus-1/system-services'
 /usr/bin/install -c -m 644 src/org.bluez.service '/usr/share/dbus-1/system-services'
 /usr/bin/mkdir -p '/usr/local/share/zsh/site-functions'
 /usr/bin/install -c -m 644 completion/zsh/_bluetoothctl '/usr/local/share/zsh/site-functions'
 /usr/bin/mkdir -p '/usr/local/share/man/man1'
 /usr/bin/install -c -m 644 monitor/btmon.1 tools/rctest.1 tools/l2ping.1 tools/btattach.1 tools/isotest.1 '/usr/local/share/man/man1'
 /usr/bin/mkdir -p '/usr/local/share/man/man8'
 /usr/bin/install -c -m 644 src/bluetoothd.8 '/usr/local/share/man/man8'
 /usr/bin/mkdir -p '/lib/systemd/system'
 /usr/bin/install -c -m 644 src/bluetooth.service '/lib/systemd/system'
 /usr/bin/mkdir -p '/usr/lib/systemd/user'
 /usr/bin/install -c -m 644 obexd/src/obex.service '/usr/lib/systemd/user'以上で最新版の BlueZ のインストールが完了しました。
バージョンを確認する
あとは以下のようにバージョンを確認すると最新版の BlueZ がインストールされていることが確認できます。bluetoothctlが BlueZ のコマンドです。
$ bluetoothctl -v
bluetoothctl: 5.66まとめ
Ubuntu に 最新版の BlueZ をインストールする手順をまとめました。今回は Python で Bluetooth を扱うライブラリで最新の BlueZ が必要であったためインストールしました。同じような状況の方の参考になれば幸いです。