2
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?

概要

pythonのバージョン管理にPyenvを使っていたが、asdfが便利そうなのでそちらに移行した。

asdfとは

簡単に言うと複数の言語やツールをまとめてバージョン管理できるコマンドラインツールです。
使い方などは下記が詳しいです。

環境

  • M2 Macbook
  • MacOS Sonoma 14.4

1. pyenvの削除

消さなくても動くと思いますが、きれいにしたかったのでまずpyenvを消しました。

$ pyenv versions
$ pyenv uninstall 3.12.2
$ brew uninstall pyenv-virtualenv
$ brew uninstall pyenv
$ rm -rf ~/.pyenv

2. asdfのインストール

公式ドキュメントを見ながらインストールしていきます。

#依存関係のインストール
$ brew install coreutils curl git

# asdfのダウンロード
$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
# 下記でもインストール可能ですが、公式としてはgit cloneを推奨しているようです
$ brew install asdf  

# パスを通す
$ echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

# インストールできているか確認
$ asdf --version    

3. pythonのインストール

# pythonインストールの前にプラグインを入れます。
$ asdf plugin-add python

# インストールできるpythonの一覧を表示
$ asdf list-all python

# 必要な依存関係のインストール
$ brew install openssl readline sqlite3 xz zlib tcl-tk

# pythonをインストール
$ asdf install python {バージョン}

# インストールされたバージョンを確認
asdf list python

4.バージョンの切り替え

# グローバルで設定
$ asdf global python {バージョン}
# ローカルで設定
$ asdf local python {バージョン}
# 現在のバージョンを確認
$ asdf current python

プラグインの更新

$ asdf plugin-update --all
$ asdf plugin-update <plugin_name>

# インストールしたプラグインの確認
$ asdf plugin list

# それぞれのバージョン確認
$ asdf current 

asdf自体の更新

$ asdf update

参考

2
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
2
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?