0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

update-alternativesの使い方

0
Last updated at Posted at 2026-08-15

はじめに

update-alternatives は Debian 系 Linux が採用する「複数の実装を持つコマンドを統一的に管理する仕組み」 で、ユーザーやシステムが どの実装を「標準」として使うかを切り替えるためのフレームワーク。
コマンドは大きく 管理・設定・参照 の3系統に分かれる。
update-alternatives の根本思想は 複数のコマンド実装を OS 全体で一貫して扱う」ことにある。

例えば、editorコマンドをvimやnanoやemacsのいずれかに割り当てたり、javaをOpenJDKやOracleJDKのいずれかに割り当てたり、それらを「役割名(リンク名)」で抽象化し、どの実装を使うかをシステム全体で統一的に切り替えることができる。

優先度について

各実装にはpriority(優先度)が付与されており、自動モードでは最も優先度の高い実装が選ばれる

手動モード(manual)と自動モード(auto)について

手動モードと自動モードの2種類存在しており、手動モードではユーザが自ら設定したものが選択され、自動モードが最も優先度が高いものが選ばれる。デフォルト(apt等のパッケージ管理ソフトが設定したもの)では自動モードが設定されている。

コマンドについて

管理・設定・参照の3種類あるが、管理についてはaptで管理していくだけなら必要がないので参照と設定について記載する。

参照系コマンドについて

alternatives を使っているライブラリ一覧を確認

update-alternatives --get-selections
awk                            auto     /usr/bin/gawk
builtins.7.gz                  auto     /usr/share/man/man7/bash-builtins.7.gz
c++                            auto     /usr/bin/g++
c89                            auto     /usr/bin/c89-gcc
c99                            auto     /usr/bin/c99-gcc
cc                             auto     /usr/bin/gcc
cpp                            auto     /usr/bin/cpp
editor                         auto     /bin/nano
ex                             auto     /usr/bin/vim.basic
fakeroot                       auto     /usr/bin/fakeroot-sysv
fonts-japanese-gothic.ttf      auto     /usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf
fonts-japanese-mincho.ttf      auto     /usr/share/fonts/truetype/takao-mincho/TakaoPMincho.ttf
infobrowser                    auto     /usr/bin/info
jsondiff                       auto     /usr/bin/json-patch-jsondiff
libblas.so.3-x86_64-linux-gnu  auto     /usr/lib/x86_64-linux-gnu/blas/libblas.so.3
liblapack.so.3-x86_64-linux-gnu auto     /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3
lzma                           auto     /usr/bin/xz
my.cnf                         auto     /etc/mysql/my.cnf.fallback
nc                             auto     /bin/nc.openbsd
newt-palette                   auto     /etc/newt/palette.ubuntu
pager                          auto     /usr/bin/less
pico                           auto     /bin/nano
pinentry                       auto     /usr/bin/pinentry-curses
pybabel                        auto     /usr/bin/pybabel-python3
rmt                            auto     /usr/sbin/rmt-tar
rview                          auto     /usr/bin/vim.basic
rvim                           auto     /usr/bin/vim.basic
sudo                           auto     /usr/lib/cargo/bin/sudo
vi                             auto     /usr/bin/vim.basic
view                           auto     /usr/bin/vim.basic
vim                            auto     /usr/bin/vim.basic
vimdiff                        auto     /usr/bin/vim.basic
vtrgb                          auto     /etc/console-setup/vtrgb
which                          auto     /usr/bin/which.debianutils
x-cursor-theme                 auto     /usr/share/icons/Adwaita/cursor.theme

alternativesの名前とモードと実装先のファイルパスが一覧で表示される。

fonts-japanese-mincho.ttfを例に実装一覧や設定モードやpriorityを見る(以下同様)

update-alternatives --display fonts-japanese-mincho.ttf
fonts-japanese-gothic.ttf - auto mode
  link best version is /usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf
  link currently points to /usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf
  link fonts-japanese-gothic.ttf is /usr/share/fonts/truetype/fonts-japanese-gothic.ttf
/usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf - priority 120
/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf - priority 100
/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf - priority 130

autoモードでTakaoゴシックが選ばれていることがわかる。

設定系コマンドについて

対話モードで切り替える(autoモードあるいはmanualモードでどれかを設定する)

sudo update-alternatives --config fonts-japanese-gothic.ttf
There are 3 choices for the alternative fonts-japanese-gothic.ttf (providing /usr/share/fonts/truetype/fonts-japanese-gothic.ttf).

  Selection    Path                                                     Priority   Status
------------------------------------------------------------
* 0            /usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf   130       auto mode
  1            /usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf     120       manual mode
  2            /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf         100       manual mode
  3            /usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf   130       manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf to provide /usr/share/fonts/truetype/fonts-japanese-gothic.ttf (fonts-japanese-gothic.ttf) in manual mode

コマンド形式で手動モードのどれかを設定

sudo update-alternatives --set fonts-japanese-gothic.ttf /usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf

自動モードに設定する

update-alternatives --auto fonts-japanese-gothic.ttf
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?