DEV Community

runeleaf
runeleaf

Posted on

2 1

macにasdfをinstallする

asdfってなに?

https://asdf-vm.com/

asdfとは各種プログラミング言語のバージョン管理を行うことができるクライアントツールです。
rubyだとrbenv、nodejsだとnodenv、またそれらを一括で管理できるようにanyenvといったコマンドツールを利用していましたが、昨今の開発現場では様々な言語・ミドルウェアが利用されるため、もともとanyenvで管理していたものをasdfに乗り換えてみようということです。

Dockerに閉じ込めてしまえばいいのでは?と思うこともありますが、まあそれはそれで・・・といった感じです。

準備

Getting Startedの通りに進めていけばすんなり設定できると思います。

いくつか方法はありますが、今回はmac上でかつzshを利用しているシーンでのインストール方法をいくつか記載します。

git clone

gitとcurlはインストールされている前提です。

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
Enter fullscreen mode Exit fullscreen mode

branchは適時確認します。

$ echo '. $HOME/.asdf/asdf.sh' >> ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

zshは再読み込みしておきます。

$ asdf version
Enter fullscreen mode Exit fullscreen mode

sheldon

zshのプラグインマネージャにsheldonを利用しているので、その設定を記載します。
sheldonのインストールや設定はまた別の機会にします。

vim ~/.sheldon/plugins.toml

[plugins.asdf]
github = "asdf-vm/asdf"

$ asdf version
Enter fullscreen mode Exit fullscreen mode

zinit

私はsheldonに移行したため、zinitは過去の設定なのですがこちらも記載します。

$ vim ~/.zshrc

zinit light asdf-vm/asdf

$ asdf version
Enter fullscreen mode Exit fullscreen mode

試す

以下のコマンドでインストールできるプラグインの一覧が出力されます。

$ asdf plugin list all
Enter fullscreen mode Exit fullscreen mode

rubyプラグインを追加

$ asdf plugin add ruby
Enter fullscreen mode Exit fullscreen mode

rubyをインストール

$ asdf list all ruby
...
3.1.2
3.2.0-dev
...

$ asdf install ruby 3.1.2
Enter fullscreen mode Exit fullscreen mode

システム全体で利用、またはプロジェクト毎に設定します。

$ asdf global ruby 3.1.2

or

$ cd prj1
$ asdf local ruby 3.2.0-dev
Enter fullscreen mode Exit fullscreen mode

最後に

同様にredisやpostgresもインストールしてバージョン管理できますが、最初に言ったとおり正直それはDockerでいいかな、という気がしています。

とはいえasdfはかなり多くの言語を一括で管理できるので、これまでバラけていたバージョン管理が多少楽にはなるのではないかなと思います。

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay