Notebook

これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。

HTML ファイル生成日時: 2025/12/17 11:43:53.312 (台灣標準時)

pkg_alternatives の使い方

pkgsrc では、 ffmpeg や python などはバージョンの異なる複数のパッケー ジがあり、バージョンの異なる複数のパッケージをインストールすることがで きる。したがって、あるときは python3.13 を使い、別のときは python3.12 を使う、ということをパッケージをインストールし直すことなく行うことがで きる。しかし、パッケージによっては、 python や python3 や ffmpeg とい う実行ファイルの存在を期待するものがあり、場合によっては問題が起きるで ござる。

pkgsrc-users に python3 というシンボリックリンクを簡便に作ったり管理したりする方法 が紹介されていたでござる。 pkgtools/pkg_alternatives を使え ばよいとのことでござった。

pkgtools/pkg_alternatives をインストールすると、多数のシェルスクリプト が作られ /usr/pkg/bin に置かれるでござる。例えば、 /usr/pkg/bin/python3 や /usr/pkg/bin/ffmpeg などが作られるでござる。問 題は、 /usr/pkg/bin/python3 や /usr/pkg/bin/ffmpeg が期待するバージョ ンのものを指し示していないことがあることでござる。例えば、 /usr/pkg/bin/python3 は python3.10 を指し示していて、 /usr/pkg/bin/ffmpeg は ffmpeg2 を指し示しているでござる。


# /usr/pkg/bin/python3 --version
Python 3.10.18
# /usr/pkg/bin/ffmpeg -version
ffmpeg version 2.8.22 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 10.5.0 (nb3 20231008)
configuration: --enable-avfilter --enable-postproc --disable-ffplay --disable-mmx --disable-mmxext --enable-fontconfig --enable-libfreetype --enable-libass --disable-htmlpages --enable-gnutls --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-openssl --disable-libpulse --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libspeex --enable-libxvid --enable-libx264 --enable-libx265 --enable-vdpau --enable-vaapi --enable-libvpx --enable-libxcb --enable-libxcb-shape --enable-libxcb-shm --enable-libxcb-xfixes --enable-libbluray --cc=gcc --disable-debug --disable-optimizations --disable-stripping --enable-gpl --enable-pthreads --enable-shared --mandir=/usr/pkg/man --prefix=/usr/pkg --progs-suffix=2 --datadir=/usr/pkg/share/ffmpeg2 --docdir=/usr/pkg/share/doc/ffmpeg2 --incdir=/usr/pkg/include/ffmpeg2 --libdir=/usr/pkg/lib/ffmpeg2 --shlibdir=/usr/pkg/lib/ffmpeg2 --enable-runtime-cpudetect
libavutil      54. 31.100 / 54. 31.100
libavcodec     56. 60.100 / 56. 60.100
libavformat    56. 40.101 / 56. 40.101
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 40.101 /  5. 40.101
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  2.101 /  1.  2.101
libpostproc    53.  3.100 / 53.  3.100

現在の設定を見るためには以下のようにすればよいようでござる。


# pkg_alternatives status python313
`bin/idle' points to `/usr/pkg/bin/idle3.12'
    candidate: /usr/pkg/bin/idle3.12
    candidate: /usr/pkg/bin/idle3.13
`bin/pydoc' points to `/usr/pkg/bin/pydoc2.7'
    candidate: /usr/pkg/bin/pydoc2.7
    candidate: /usr/pkg/bin/pydoc3.10
    candidate: /usr/pkg/bin/pydoc3.11
    candidate: /usr/pkg/bin/pydoc3.12
    candidate: /usr/pkg/bin/pydoc3.13
    candidate: /usr/pkg/bin/pydoc3.9
`bin/python' points to `/usr/pkg/bin/python2.7'
    candidate: /usr/pkg/bin/python2.7
    candidate: /usr/pkg/bin/python3.10
    candidate: /usr/pkg/bin/python3.11
    candidate: /usr/pkg/bin/python3.12
    candidate: /usr/pkg/bin/python3.13
    candidate: /usr/pkg/bin/python3.9
`bin/python3' points to `/usr/pkg/bin/python3.10'
    candidate: /usr/pkg/bin/python3.10
    candidate: /usr/pkg/bin/python3.11
    candidate: /usr/pkg/bin/python3.12
    candidate: /usr/pkg/bin/python3.13
    candidate: /usr/pkg/bin/python3.9

/usr/pkg/bin/python3 は python3.10 を指し示しているでござる。これを、 変更するには、例えば、以下のようにすればよいようでござる。


# pkg_alternatives manual python313
pkg_alternatives: modifying configuration from `/usr/pkg/etc/pkg_alternatives/usr/pkg/bin/idle'
pkg_alternatives: modifying configuration from `/usr/pkg/etc/pkg_alternatives/usr/pkg/bin/pydoc'
pkg_alternatives: modifying configuration from `/usr/pkg/etc/pkg_alternatives/usr/pkg/bin/python'
pkg_alternatives: modifying configuration from `/usr/pkg/etc/pkg_alternatives/usr/pkg/bin/python3'

すると、 /usr/pkg/bin/python3 は python3.13 を指し示すようになったでござる。


# pkg_alternatives status python313
`bin/idle' points to `/usr/pkg/bin/idle3.13'
    candidate: /usr/pkg/bin/idle3.12
    candidate: /usr/pkg/bin/idle3.13
`bin/pydoc' points to `/usr/pkg/bin/pydoc3.13'
    candidate: /usr/pkg/bin/pydoc2.7
    candidate: /usr/pkg/bin/pydoc3.10
    candidate: /usr/pkg/bin/pydoc3.11
    candidate: /usr/pkg/bin/pydoc3.12
    candidate: /usr/pkg/bin/pydoc3.13
    candidate: /usr/pkg/bin/pydoc3.9
`bin/python' points to `/usr/pkg/bin/python3.13'
    candidate: /usr/pkg/bin/python2.7
    candidate: /usr/pkg/bin/python3.10
    candidate: /usr/pkg/bin/python3.11
    candidate: /usr/pkg/bin/python3.12
    candidate: /usr/pkg/bin/python3.13
    candidate: /usr/pkg/bin/python3.9
`bin/python3' points to `/usr/pkg/bin/python3.13'
    candidate: /usr/pkg/bin/python3.10
    candidate: /usr/pkg/bin/python3.11
    candidate: /usr/pkg/bin/python3.12
    candidate: /usr/pkg/bin/python3.13
    candidate: /usr/pkg/bin/python3.9

同様に、 ffmpeg についても設定してみるでござる。


# pkg_alternatives status ffmpeg8
`bin/ffmpeg' points to `/usr/pkg/bin/ffmpeg2'
    candidate: /usr/pkg/bin/ffmpeg2
    candidate: /usr/pkg/bin/ffmpeg3
    candidate: /usr/pkg/bin/ffmpeg4
    candidate: /usr/pkg/bin/ffmpeg5
    candidate: /usr/pkg/bin/ffmpeg6
    candidate: /usr/pkg/bin/ffmpeg7
    candidate: /usr/pkg/bin/ffmpeg8
`bin/ffprobe' points to `/usr/pkg/bin/ffprobe2'
    candidate: /usr/pkg/bin/ffprobe2
    candidate: /usr/pkg/bin/ffprobe3
    candidate: /usr/pkg/bin/ffprobe4
    candidate: /usr/pkg/bin/ffprobe5
    candidate: /usr/pkg/bin/ffprobe6
    candidate: /usr/pkg/bin/ffprobe7
    candidate: /usr/pkg/bin/ffprobe8
# pkg_alternatives manual ffmpeg8
pkg_alternatives: modifying configuration from `/usr/pkg/etc/pkg_alternatives/usr/pkg/bin/ffmpeg'
pkg_alternatives: modifying configuration from `/usr/pkg/etc/pkg_alternatives/usr/pkg/bin/ffprobe'
# pkg_alternatives status ffmpeg8
`bin/ffmpeg' points to `/usr/pkg/bin/ffmpeg8'
    candidate: /usr/pkg/bin/ffmpeg2
    candidate: /usr/pkg/bin/ffmpeg3
    candidate: /usr/pkg/bin/ffmpeg4
    candidate: /usr/pkg/bin/ffmpeg5
    candidate: /usr/pkg/bin/ffmpeg6
    candidate: /usr/pkg/bin/ffmpeg7
    candidate: /usr/pkg/bin/ffmpeg8
`bin/ffprobe' points to `/usr/pkg/bin/ffprobe8'
    candidate: /usr/pkg/bin/ffprobe2
    candidate: /usr/pkg/bin/ffprobe3
    candidate: /usr/pkg/bin/ffprobe4
    candidate: /usr/pkg/bin/ffprobe5
    candidate: /usr/pkg/bin/ffprobe6
    candidate: /usr/pkg/bin/ffprobe7
    candidate: /usr/pkg/bin/ffprobe8

これで、 /usr/pkg/bin/ffmpeg を実行すると、 ffmpeg8 が選ばれるようになっ たでござる。



Frequently accessed files

  1. Misc___Taiwan/20240207_00.html
  2. Computer___TeX/20240410_00.html
  3. Computer___TeX/20231107_00.html
  4. Misc___Taiwan/20240819_00.html
  5. Computer___TeX/20230726_01.html
  6. Book___Chinese/20240424_00.html
  7. Computer___TeX/20240411_00.html
  8. Computer___Python/20250330_00.html
  9. Misc___Taiwan/20240903_01.html
  10. Misc___Japan/20240718_00.html
  11. Computer___NetBSD/20250301_01.html
  12. Computer___Network/20230516_00.html
  13. Computer___TeX/20240414_00.html
  14. Computer___NetBSD/20230119_00.html
  15. Computer___TeX/20240414_01.html
  16. Computer___FreeBSD/20220621_0.html
  17. Computer___Network/20240130_00.html
  18. Computer___Python/20220715_0.html
  19. Computer___Network/20241214_00.html
  20. Computer___Python/20220518_0.html
  21. Computer___NetBSD/20240810_00.html
  22. Computer___NetBSD/20250409_00.html
  23. Computer___Debian/20230102_00.html
  24. Computer___Python/20240101_00.html
  25. Computer___NetBSD/20250113_00.html
  26. Computer___NetBSD/20241102_00.html
  27. Computer___NetBSD/20240805_03.html
  28. Misc___Japan/20240610_00.html
  29. Computer___Hardware/20240820_00.html
  30. Computer___Python/20220410_0.html


HTML file generated by Kinoshita Daisuke.