0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

asdf(v0.16.0)を使ったPython環境構築

Last updated at Posted at 2025-02-12

はじめに

バージョン管理システムの1つであるasdfがGoによって新造されて仕様がガラッと変わった.
変わるのはいいんだけど,Goの環境もasdfで管理していたため,Goを管理するasdfを動かすためにGoをインストールする必要がある.
ぜったい面倒になる気がしたので,コンパイル済みのバイナリファイルを持ってくることにする.

環境

Machu@GQuuuuuuX:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
...
Machu@GQuuuuuuX:~$

WSLのbash環境にv0.16.2を実装する手順をメモする.

ちなみにv0.15.0だと以下のようなNOTICEが赤文字で出てくる.

Machu@GQuuuuuuX:~$ asdf --version
----------

NOTICE:

You have tried to upgrade to asdf 0.16.0 or newer. Versions 0.16.0 is a
complete rewrite of asdf in Go. This text is being printed by the older
Bash implementation. If you are seeing this you have not migrated to
asdf 0.16.0. Please follow the instructions on the upgrade guide to
migrate to the new version.

Aside from this notice, this older Bash implementation works as it did
in asdf version 0.15.0 and older.

Migration guide: https://asdf-vm.com/guide/upgrading-to-v0-16
asdf website: https://asdf-vm.com
Source code: https://github.com/asdf-vm/asdf


v0.15.0-0146164
Machu@GQuuuuuuX:~$

Install

基本

Macじゃないのでgitからバイナリを持ってきて環境構築.

やることは,バイナリを$PATHに置くだけなので簡単だが,$PATH自体が色々ある.

Machu@GQuuuuuuX:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Users/YuzurihaAMATE/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/YuzurihaAMATE/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin
Machu@GQuuuuuuX:~$

自作や外部からのインストールは/usr/local/sbinもしくは/usr/local/binに保存しておくと良さそう

sbinは管理者用の実行ファイルを置くのが通常なので、/usr/local/binに取り敢えずasdfバイナリをおいておく.

cd /usr/local/bin # PATHへの移動
sudo curl -OL https://github.com/asdf-vm/asdf/releases/download/v0.16.2/asdf-v0.16.2-linux-amd64.tar.gz # バイナリDownload
sudo tar -zxvf asdf-v0.16.2-linux-amd64.tar.gz # 解凍
sudo rm asdf-v0.16.2-linux-amd64.tar.gz # 圧縮ファイルを削除
cd - # 元いたディレクトリに戻る
echo 'export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"' >> ~/.bashrc # shimディレクトリを$PATH追加
source ~/.bashrc # bashrcをリロード

適宜読み替えて.

任意

ASDF_DATA_DIR(データディレクトリ)の設定

echo 'export ASDF_DATA_DIR="/your/custom/data/dir"' >> ~/.bashrc
source ~/.bashrc

シェル補完の設定

echo '. <(asdf completion bash)' >> ~/.bashrc
source ~/.bashrc

動作確認

Machu@GQuuuuuuX:~$ asdf version
...
RESOURCES
GitHub: https://github.com/asdf-vm/asdf
Docs:   https://asdf-vm.com


"Late but latest"
-- Rajinikanth
Machu@GQuuuuuuX:~$ 

Plugin (Python) Install demo

asdf plugin add python # プラグイン追加
sudo apt update; sudo apt install -y build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev # なんか必要そうなもの詰め合わせセット
asdf install python 3.12.9 # Pythonのインストール
asdf set python 3.12.9 # Pythonをメイン環境に
python --version

いろいろなもの詰め合わせセットはasdfの過去の経験から

言語のVersionの状況のメモ

動作確認

Machu@GQuuuuuuX:~$ asdf current
Name            Version         Source                    Installed
python          3.12.9          /home/Machu/.tool-versions true
Machu@GQuuuuuuX:~$

うまく行ってないとき

Machu@GQuuuuuuX:~$ asdf current
Name            Version         Source          Installed
python          ______          ______
Machu@GQuuuuuuX:~$ asdf list

v0.15.0以前とv0.16.0の違い

今後

インストールが結構面倒になったので,バージョン管理システムをpyenvanyenvasdfと移行してきたけれど,次はmiseかもしれないな,と思う.

さいごに

「よくわかんないけど、なんかわかった!」

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?