Ubuntu 24.04 へ asdf をインストールして言語 / ツールのバージョンを管理する
asdf は複数の言語やツールに対応したバージョンマネージャです。 今回は Ubuntu 24.04 へ asdf をインストールしてみます。
検証環境¶
| 対象 | バージョン |
|---|---|
| Ubuntu | 24.04 |
| asdf | v0.13.1-0586b37 |
インストールする¶
asdf をインストールするには事前に curl と git をインストールしておく必要があります。 apt でインストールしておきます。
~/.asdf へ git clone します。
必要な環境変数を ~/.bashrc へ追記します。
~/.bashrc へ追記した内容を反映します。
これでインストール完了です。
基本的な使い方¶
asdf の基本的な利用の流れは以下です。
- 各言語/ツールのプラグインをインストールする
- 各言語/ツールの指定バージョンをインストールする
- インストールしたバージョンを利用出来るように設定する
asdf でよく利用するコマンドには以下などがあります。
| コマンド | 説明 |
|---|---|
asdf update |
asdf 自身をアップデートする |
asdf plugin list |
インストール済みのプラグイン一覧を表示する |
asdf plugin list all |
インストール可能なプラグイン一覧を表示する |
asdf list |
インストール済みのプラグイン・バージョンを表示する |
asdf list [PLUGIN] |
インストール済みの NAME プラグイン・バージョンを表示する |
asdf list all [PLUGIN] |
インストール可能な NAME プラグインのバージョン一覧を表示する |
asdf plugin add [PLUGIN] |
NAME プラグインをインストールする |
asdf plugin remove [PLUGIN] |
NAME プラグインをアンインストールする |
asdf plugin update [PLUGIN] |
NAME プラグインをアップデートする |
asdf plugin update --all |
インストール済みのプラグインを全てアップデートする |
asdf install [PACKAGE] |
PACKAGE をインストールする |
asdf install [PACKAGE] [VERSION] |
指定バージョンの PACKAGE をインストールする |
asdf uninstall [PACKAGE] [VERSION] |
指定バージョンの PACKAGE をアンインストールする |
asdf global [PACKAGE] [VERSION] |
システム全体で利用する PACKAGE のバージョンを指定する |
asdf local [PACKAGE] [VERSION] |
特定のディレクトリ配下のみで利用する PACKAGE のバージョンを指定する |
Python プラグインをインストールする¶
試しに Python プラグインをインストールしてみます。 Python プラグインを利用する為に必要なソフトウェアをインストールしておきます。
apt -y install \
build-essential \
curl \
libbz2-dev \
libffi-dev \
liblzma-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libxml2-dev \
libxmlsec1-dev \
tk-dev \
xz-utils \
zlib1g-dev
まず Python 用のプラグインをインストールします。 asdf plugin add python を実行します。
インストール可能な Python のバージョンを確認します。 asdf list all python を実行します。
今回はバージョン 3.12.1 をインストールすることにします。 asdf install python 3.12.1 を実行します。
インストールした Python 3.12.1 がシステム全体で利用されるように設定します。
asdf list を実行すると 3.12.1 の横にアスタリスクが付いており、「システム全体で利用されている」ことが分かります。
実際に python や python3 のバージョンを確認すると 3.12.1 が利用されていることが分かります。
Python プラグインは内部で pyenv を利用している¶
Python プラグインは下記の GitHub リポジトリで管理されているようです。
このリポジトリの内容を見ていくと、例えば asdf-python/bin/help.links などに「内部的には pyenv を利用している」旨の記載が見受けられます。
# Output should be <title>: <link>
echo 'home-page: https://github.com/danhper/asdf-python
dependencies: https://github.com/pyenv/pyenv/wiki#suggested-build-environment
troubleshooting: https://github.com/pyenv/pyenv/wiki/Common-build-problems
'
尚、Python プラグイン (≒ pyenv) 以外にも poetry や rye も利用可能なようです。
# asdf plugin list all | grep -e asdf-poetry -e asdf-rye
poetry https://github.com/asdf-community/asdf-poetry.git
rye https://github.com/Azuki-bar/asdf-rye
参考¶
# asdf --help
version: v0.13.1-0586b37
MANAGE PLUGINS
asdf plugin add <name> [<git-url>] Add a plugin from the plugin repo OR,
add a Git repo as a plugin by
specifying the name and repo url
asdf plugin list [--urls] [--refs] List installed plugins. Optionally show
git urls and git-ref
asdf plugin list all List plugins registered on asdf-plugins
repository with URLs
asdf plugin remove <name> Remove plugin and package versions
asdf plugin update <name> [<git-ref>] Update a plugin to latest commit on
default branch or a particular git-ref
asdf plugin update --all Update all plugins to latest commit on
default branch
MANAGE PACKAGES
asdf current Display current version set or being
used for all packages
asdf current <name> Display current version set or being
used for package
asdf global <name> <version> Set the package global version
asdf global <name> latest[:<version>] Set the package global version to the
latest provided version
asdf help <name> [<version>] Output documentation for plugin and tool
asdf install Install all the package versions listed
in the .tool-versions file
asdf install <name> Install one tool at the version
specified in the .tool-versions file
asdf install <name> <version> Install a specific version of a package
asdf install <name> latest[:<version>] Install the latest stable version of a
package, or with optional version,
install the latest stable version that
begins with the given string
asdf latest <name> [<version>] Show latest stable version of a package
asdf latest --all Show latest stable version of all the
packages and if they are installed
asdf list <name> [version] List installed versions of a package and
optionally filter the versions
asdf list all <name> [<version>] List all versions of a package and
optionally filter the returned versions
asdf local <name> <version> Set the package local version
asdf local <name> latest[:<version>] Set the package local version to the
latest provided version
asdf shell <name> <version> Set the package version to
`ASDF_${LANG}_VERSION` in the current shell
asdf uninstall <name> <version> Remove a specific version of a package
asdf where <name> [<version>] Display install path for an installed
or current version
asdf which <command> Display the path to an executable
UTILS
asdf exec <command> [args...] Executes the command shim for current version
asdf env <command> [util] Runs util (default: `env`) inside the
environment used for command shim execution.
asdf info Print OS, Shell and ASDF debug information.
asdf reshim <name> <version> Recreate shims for version of a package
asdf shim-versions <command> List the plugins and versions that
provide a command
asdf update Update asdf to the latest stable release
asdf update --head Update asdf to the latest on the master branch
RESOURCES
GitHub: https://github.com/asdf-vm/asdf
Docs: https://asdf-vm.com
"Late but latest"
-- Rajinikanth