LoginSignup
1
1

More than 1 year has passed since last update.

asdfインストール中に書いた備忘録

Posted at

はじめに

ここと最後の「おわりに」は備忘録を書いた後の追記です。備忘録だけでは伝わらないかなーと思ったので、色々と書き足しておきます。

私の環境:

  • M1 MacBook Air
  • シェル: Zsh
  • バージョン管理ツール: Homebrew

この備忘録を書くに至った流れ:

  1. HomebrewでNode.jsのバージョン管理するの難しいな
  2. asdfっていうのあるらしいね
  3. 触ってみるか
  4. いつでも消せるように備忘録書こう

それではお楽しみください。

asdf触ろう

entrypoint:

インストール

brew install asdf

重要そうなアウトプット

==> Caveats
To use asdf, add the following line to your ~/.zshrc:
  . /opt/homebrew/opt/asdf/libexec/asdf.sh

Restart your terminal for the settings to take effect.

zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions

これは一旦置いておいてGetting Started | asdf #_3-install-asdfをみると、ohmyzshのプラグインがあるらしい。

  1. ~/.zshrcpluginsasdfを追加
  2. git clone https://github.com/asdf-vm/asdf.git ~/.asdf

入った

$ asdf
version: v0.10.2-eaf2215

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 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 uninstall <name> <version>         Remove a specific version of a package
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 where <name> [<version>]           Display install path for an installed
                                        or current version
asdf which <command>                    Display the path to an executable
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 global <name> <version>            Set the package global version
asdf global <name> latest[:<version>]   Set the package global version to the
                                        latest provided version
asdf shell <name> <version>             Set the package version to
                                        `ASDF_${LANG}_VERSION` in the current shell
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 help <name> [<version>]            Output documentation for plugin and tool


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

使用例

以下、Node.jsを使う例

プラグインを追加してから管理するらしい。Node.js用のやつはasdf-vm/asdf-nodejs: Node.js plugin for asdf version manager

Getting Started | asdf #_4-install-a-pluginをみるとプラグインを入れる前にプラグインが依存しているツールを入れる必要があるっぽいんだけど、asdf-vm/asdf-nodejs: Node.js plugin for asdf version manager #installをみるといらなさそう。スキップしてプラグインを入れる(事後: 問題なさそうだった)

$ asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

アウトプット何もなかったんだが大丈夫か。以下コマンド集

  • 全てのバージョンのリストアップ: asdf list all nodejs
  • 特定バージョンのリストアップ: asdf list all nodejs 14
  • 最新バージョンのインストール: asdf install nodejs latest
  • ローカルのツール群のリストアップ: asdf list
  • グローバルのバージョンの設定: asdf global nodejs latest
    • ~/.tool-versionsnodejs 18.4.0の行が追加された
  • ローカルのバージョン設定: asdf local nodejs latest
    • $PWD/.tool-versionsnodejs 18.4.0の行が追加された

プチトラブルシューティング

  • asdf install nodejs 14したのに入らない
    • asdf install nodejs 14.19.3のように詳細にバージョン指定しないといけないっぽい
  • BUILD FAILEDしたんだけど!?!?!?!?!?????
    • asdf - node.js ディレクトリごとのバージョン管理の最後らへん
    • arch -x86_64 asdf install nodejs 14.19.3って感じでアーキテクチャ指定したら入った
    • arch -x86_64 npm installって感じでインストール後もアーキテクチャ指定しないといけないらしいんだけど、私の手元では指定なしでもできた(はず)

おわりに

ここまで読んでいただきありがとうございました。まだインストールしかしていませんが、asdf良さそうですね。ディレクトリごとに.tool-versionsというテキストファイルでバージョンを指定するというやり方、素敵ですね。確実にバージョンを揃えられるためgit管理とも相性が良さそうだなーと思ったりしました。

ちょっと宣伝します。私、この春(※2022年4月)から東京工業大学デジタル創作同好会traPに入りました。そこでIntelliJをインストールするだけの記事というものを書いたのですが、特に大学関係者の方に是非読んで欲しいです。理由は読んだら(たぶん)わかります。

IntelliJもasdfで管理できるのかなーと思って調べてみましたが、できそうですね。ただ一度入れたものを消すのはやはり骨が折れるので、これをやるのはまた今度気が向いた時に...

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