我在安装asdf时写下的备忘录
首先
这里和最后的「结束语」是在写备忘录之后的补充内容。因为觉得仅仅有备忘录可能无法完全传达,所以写了一些其他的内容补充进去。
我的环境
-
- M1 MacBook Air
-
- シェル: Zsh
Oh My Zsh使用
バージョン管理ツール: Homebrew
写这个备忘录的原因如下:
-
- 在Homebrew上管理Node.js的版本真的很难
-
- 听说有个asdf什么的工具
-
- 可以试试看
- 先备忘录下,随时可以删掉
请享受吧。
让我们碰一碰
切入点:
-
- asdf-vm/asdf: Extendable version manager with support for Ruby, Node.js, Elixir, Erlang & more
- Getting Started | asdf
安装
brew 安装 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的插件。
- ohmyzsh/plugins/asdf at master · ohmyzsh/ohmyzsh
-
- 将asdf添加到~/.zshrc的插件列表中
- 克隆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:用于asdf版本管理器的Node.js插件。
开始 | 当查看#_4-install-a-plugin时,似乎需要在安装插件之前安装插件依赖的工具,但根据asdf-vm/asdf-nodejs的#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-versionsにnodejs 18.4.0の行が追加された
ローカルのバージョン設定: asdf local nodejs latest
$PWD/.tool-versionsにnodejs 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,所以我进行了一些调查,看起来是可以的。不过,毕竟将安装的内容卸载掉有点麻烦,所以我可能下次心情好的时候再来做这件事情…