rtx - ランタイムエグゼキュータ(asdf rustクローン)

(Runtime Executor (asdf rust clone))

Created at: 2023-01-09 22:44:21
Language: Rust
License: MIT

ティッカー

Crates.io ライセンス: MIT ティッカー コデコフ 不和

多言語ランタイムマネージャ(asdf rustクローン)

30秒デモ

次に、rtx を使用して、ファイルを使用してプロジェクトに nodejsjq をインストールする方法を示します。ハイパーファインは、を使用してパフォーマンスを示すために使用されます RTX 対 ASDF.(パフォーマンスを参照)。 呼び出しは、シムではなくバイナリへの実際のパスを提供することに注意してください。

.tool-versions
which node

デモ

顔立ち

  • ASDF 互換 - RTX は ASDF プラグインおよびファイルと互換性があります。ドロップイン交換として使用できます。
    .tool-versions
  • 多言語 - どの言語とも互換性があるので、nvm、nodenv、pyenvなどがどのように個別に機能するかを理解する必要はなく、1つのツールを使用するだけです。
  • 高速 - rtxはRustで書かれており、非常に高速です。ASDFよりも20倍から200倍高速です。
  • シムなし - シム(asdf で使用される)は問題を引き起こし、壊れ、オーバーヘッドを追加します。デフォルトでは使用しません。
    which node
  • より良いUX - asdfは奇妙なUXの決定でいっぱいです(好きだけでなく)。rtxを使いやすくするために注意を払いました。
    asdf plugin add
    asdf install
  • あいまい一致とエイリアス - asdf のように正確なバージョン番号を指定する必要はありません。
  • 1つのコマンドインストール - 各プラグインを手動でインストールする必要はなく、実行するだけで、必要なすべてのプラグインがインストールされます。
    rtx install

クイックスタート

rtxをインストールします(他の方法はここにあります):

$ curl https://rtx.pub/rtx-latest-macos-arm64 > ~/bin/rtx
$ chmod +x ~/bin/rtx
$ rtx --version
rtx 1.18.2

rtx をシェルにフックします。これは、まだ追加されていない場合は自動的に追加されます。 (いずれかを選択し、新しいシェルセッションを開いて変更を有効にします)。

~/bin
PATH

$ echo 'eval "$(~/bin/rtx activate bash)"' >> ~/.bashrc
$ echo 'eval "$(~/bin/rtx activate zsh)"' >> ~/.zshrc
$ echo '~/bin/rtx activate fish | source' >> ~/.config/fish/config.fish

警告

direnv を使用する場合は、rtx の前に direnv をアクティブにする必要があります。もあります Direnv内でRTXを使用する別の方法については、こちらをご覧ください

ランタイムをインストールし、デフォルトとして設定します。

$ rtx install nodejs@18
$ rtx global nodejs@18
$ node -v
v18.10.9

手記

rtx install
はオプションであり、そうでない場合はランタイムをインストールするように求められます すでにインストールされています。これは ~/.config/rtx/config.toml で設定可能です。
rtx global

目次

に関しては

RTXは、プログラミング言語とツールのバージョンを管理するためのツールです。たとえば、これを使用してインストールします プロジェクトのノード.jsおよびRubyの特定のバージョン。を使用すると、 シェルは、プロジェクトの ディレクトリ。コンピューター上の他のプロジェクトでは、異なるバージョンのセットを使用できます。

rtx activate
cd

RTXはASDFに触発され、内部でASDFの広大なプラグインエコシステムを使用しています。ただし、asdfよりもはるかに高速で、より使いやすいユーザーエクスペリエンスを備えています。 rtx と asdf の比較の詳細については、以下を参照してください。このプロジェクトの目的 ASDFのより良いフロントエンドを作成することでした。

asdf が使用するのと同じファイルを使用します。慣用バージョンとも互換性があります や .以下のレガシーバージョンファイルを参照してください。

.tool-versions
.node-version
.ruby-version

不和のrtxについてチャットしてください。

仕組み

RTX は、シェルが正しいランタイム バイナリを指すように環境変数を設定するシェル拡張機能 (例: ) としてインストールされます。あなたが ディレクトリにファイルが含まれている場合、RTXは自動的に正しいバージョンをアクティブにします。

rtx activate zsh
PATH
cd
.tool-versions

プロンプトが起動するたびに、新しい環境変数を取得するために呼び出されます。これ 非常に高速である必要があり、ディレクトリが変更されていない場合、またはファイルが更新されていない場合は早期に終了します。私のマシンでは、高速の場合は4ms、低速の場合は14msかかります。このトピックの詳細については、「パフォーマンス」を参照してください。

rtx hook-env
.tool-versions

shim ファイルを使用してランタイムが呼び出されたときに動的に検索する asdf とは異なり、rtx はランタイムが直接呼び出されるように事前に変更します。これは回避するので速いだけではありません オーバーヘッドはありますが、コマンドのように期待どおりに機能します。これも 新しいランタイムバイナリをインストールした後に実行する必要がないことを意味します。

PATH
which node
asdf reshim

RTX はランタイムを直接インストールしません。代わりに、asdf プラグインを使用してランタイムをインストールします。以下のプラグインを参照してください。

一般的なコマンドの例

rtx install nodejs@18.0.0       Install a specific version number
rtx install nodejs@18.0         Install a fuzzy version number
rtx local nodejs@18             Use node-18.x in current project
rtx global nodejs@18            Use node-18.x as default

rtx install nodejs              Install the version specified in .tool-versions
rtx local nodejs@latest         Use latest node in current directory
rtx global nodejs@system        Use system node as default

rtx x nodejs@18 -- node app.js  Run `node app.js` with the PATH pointing to node-18.x

取り付け

スタンドアロン

オンである必要はないことに注意してください。rcでアクティブ化スクリプトを実行する場合 ファイルの場合、RTX は自動的に自身を に追加します。

rtx
PATH
PATH

$ curl https://rtx.pub/install.sh | sh

またはアレルギーがある場合:

| sh

$ curl https://rtx.pub/rtx-latest-macos-arm64 > /usr/local/bin/rtx

どこに置いても構いません。したがって、または何でも使用します。

~/bin
/usr/local/bin
~/.local/share/rtx/bin/rtx

サポートされているアーキテクチャ:

  • x64
  • arm64

サポートされているプラットフォーム:

  • macos
  • linux

他に何かが必要な場合は、貨物でコンパイルしてください。

自作

自作でrtxをインストールするには2つの方法があります。推奨される方法は、 常に最新リリースを含むカスタムタップ。

$ brew install jdxcode/tap/rtx

または、更新される組み込みのタップ(自作コア)を使用することもできます Homebrewメンテナが新しいリリースのPRをマージしたら:

$ brew install rtx

貨物

貨物を使用してソースから構築する:

$ cargo install rtx-cli

Do it faster with [cargo-binstall](https://github.com/cargo-bins/cargo-binstall):

```sh-session
$ cargo install cargo-binstall
$ cargo binstall rtx-cli

メインの最新のコミットからビルドします。

$ cargo install rtx-cli --git https://github.com/jdxcode/rtx --branch main

ティッカー

RTXは、プリコンパイルされたバイナリとしてnpmで利用できます。これはノード.jsパッケージではなく、配布されたばかりです NPM経由。これは、またはを介してrtxを設定するJSプロジェクトに役立ちます。

package.json
npx

$ npm install -g @jdxcode/rtx

または、完全にインストールせずに単一のコマンドをテストする場合は、npxを使用します。

$ npx @jdxcode/rtx exec python@3.11 -- python some_script.py

GitHub リリース

GitHub から最新リリースをダウンロードします

$ curl https://github.com/jdxcode/rtx/releases/download/v1.18.2/rtx-v1.18.2-linux-x64 | tar -xJv
$ mv rtx/bin/rtx /usr/local/bin

アプト

Ubuntu/Debian にインストールする場合:

wget -qO - https://rtx.pub/gpg-key.pub | gpg --dearmor | sudo tee /usr/share/keyrings/rtx-archive-keyring.gpg 1> /dev/null
echo "deb [signed-by=/usr/share/keyrings/rtx-archive-keyring.gpg arch=amd64] https://rtx.pub/deb stable main" | sudo tee /etc/apt/sources.list.d/rtx.list
sudo apt update
sudo apt install -y rtx

警告

arm64を使用している場合は、以下を実行する必要があります。

echo "deb [signed-by=/usr/share/keyrings/rtx-archive-keyring.gpg arch=arm64] https://rtx.pub/deb stable main" | sudo tee /etc/apt/sources.list.d/rtx.list

ティッカー

Fedora、CentOS、Amazon Linux、RHEL およびその他の dnf ベースのディストリビューションの場合:

dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://rtx.pub/rpm/rtx.repo
dnf install -y rtx

ヤム

yum install -y yum-utils
yum-config-manager --add-repo https://rtx.pub/rpm/rtx.repo
yum install -y rtx

APK (近日公開予定)

アルパインリナックスの場合:

apk add rtx --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/

アウル

Arch Linux の場合:

git clone https://aur.archlinux.org/rtx.git
cd rtx
makepkg -si

その他のシェル

バッシュ

$ echo 'eval "$(rtx activate bash)"' >> ~/.bashrc

$ echo 'rtx activate fish | source' >> ~/.config/fish/config.fish

ソンシュ

ファイルはコンパイルされていないので、純粋なPythonインポートを使用して起動時間を少し短縮することができます:以下のコードを、例えば設定ファイルに追加し、

.xsh
~/.config/xonsh/rtx.py
import rtx
~/.config/xonsh/rc.xsh

from pathlib        	import Path
from xonsh.built_ins	import XSH

ctx = XSH.ctx
rtx_init = subprocess.run([Path('~/bin/rtx').expanduser(),'activate','xonsh'],capture_output=True,encoding="UTF-8").stdout
XSH.builtins.execx(rtx_init,'exec',ctx,filename='rtx')

または、引き続き /:

rc.xsh
.xonshrc

echo 'execx($(~/bin/rtx activate xonsh))' >> ~/.config/xonsh/rc.xsh # or ~/.xonshrc

シェル環境とOS環境の両方を置き換えることを考えると、設定にこれら2つが異なる設定されていないことに注意してください(一致することを確認するために設定の最後にスローされる可能性があります)

rtx
$PATH
PATH
os.environ['PATH'] = xonsh.built_ins.XSH.env.get_detyped('PATH')

他に何か?

シェルコードはほとんどないため、新しいシェルを追加することはまったく難しくありません。 このプロジェクトで。方法についてはこちらをご覧ください その他は実装されています。シェルが現在サポートされていない場合 私はあなたがあなたの統合を手伝うことを嬉しく思います。

アンインストール

rtx をアンインストールするために使用します。これにより、rtxバイナリとそのすべてのデータが削除されます。詳細については、以下を参照してください。

rtx implode
rtx implode --help

または、次のディレクトリを手動で削除して、完全にクリーンアップします。

  • ~/.local/share/rtx
    (または
    RTX_DATA_DIR
    XDG_DATA_HOME/rtx
    )
  • ~/.config/rtx
    (または
    RTX_CONFIG_DIR
    XDG_CONFIG_HOME/rtx
    )
  • Linuxの場合:(または
    ~/.cache/rtx
    RTX_CACHE_DIR
    XDG_CACHE_HOME/rtx
    )
  • macOSの場合:(
    ~/Library/Caches/rtx
    RTX_CACHE_DIR
    )

構成

.tool-versions

このファイルは、プロジェクトのランタイム バージョンを指定するために使用されます。この例 です:

.tool-versions

nodejs      18.0.0       # comments are allowed
ruby        3            # can be fuzzy version
shellcheck  latest       # also supports "latest"
jq          1.6
erlang      ref:master   # compile from vcs ref
golang      prefix:1.19  # uses the latest 1.19.x version—needed in case "1.19" is an exact match
shfmt       path:./shfmt # use a custom runtime

ファイルを手動で作成するか、rtx local を使用して自動的に作成します。 このファイル形式の詳細については、asdf のドキュメントを参照してください。

.tool-versions

レガシーバージョンのファイル

RTX は、ASDF と同様に「レガシー バージョンのファイル」をサポートしています。これらは、 や のような言語固有のファイルです。これらは、強制せずにプロジェクトのランタイムバージョンを設定するのに理想的です RTX / ASDFのような特定のツールを使用する他の開発者。

.node-version
.python-version

彼らはエイリアスをサポートしています、それはあなたがファイルを持つことができ、それが機能することを意味します RTXおよびNVMで。サポートされているレガシーバージョンのファイルの一部を次に示します。

.nvmrc
lts/hydrogen

プラグイン 「レガシー」(慣用)ファイル
結晶
.crystal-version
エリキシル
.exenv-version
ゴラン
.go-version
,
go.mod
.java
.java-version
ノード
.nvmrc
,
.node-version
ニシキヘビ
.python-version
ルビー
.ruby-version
,
Gemfile
テラフォーム
.terraform-version
, ,
.packer-version
main.tf
.yvmrc

rtx では、これらはデフォルトで有効になっています。あなたはそれらを無効にすることができます。 のプラグインによって実行されるときにこれらが解析されるときに、これらを持つことにはパフォーマンスコストがかかります。ただし、これらはキャッシュされているため、大したことではありません。 あなたも気づかないかもしれません。

rtx settings set legacy_version_file false
bin/parse-version-file

手記

ASDF ではこれらを「レガシー バージョン ファイル」と呼んでいるので、私たちもそうしています。それは暗示しているので、これは悪い名前だと思います それらは使用すべきではないということですが、IMOは絶対にそうではありません。私は「慣用的」という用語が好きです バージョン ファイルは ASDF/RTX に固有ではなく、他のツールで使用できるバージョン ファイルです。 (特定のツールに関連付けられている注目すべき例外です。

.nvmrc

グローバル設定:
~/.config/rtx/config.toml

RTX は で設定できます。次のオプションを使用できます(デフォルトが表示されます)。

~/.config/rtx/config.toml

# whether to prompt to install plugins and runtimes if they're not already installed
missing_runtime_behavior = 'prompt' # other options: 'ignore', 'warn', 'prompt', 'autoinstall'

# plugins can read the versions files used by other version managers (if enabled by the plugin)
# for example, .nvmrc in the case of nodejs's nvm
legacy_version_file = true         # enabled by default (different than asdf)

# configure `rtx install` to always keep the downloaded archive
always_keep_download = false        # deleted after install by default

# configure how frequently (in minutes) to fetch updated plugin repository changes
# this is updated whenever a new runtime is installed
# (note: this isn't currently implemented but there are plans to add it: https://github.com/jdxcode/rtx/issues/128)
plugin_autoupdate_last_check_duration = 10080 # (one week) set to 0 to disable updates

verbose = false     # set to true to see full installation output, see `RTX_VERBOSE`
asdf_compat = false # set to true to ensure .tool-versions will be compatible with asdf, see `RTX_ASDF_COMPAT`
jobs = 4            # number of plugins or runtimes to install in parallel. The default is `4`.

shorthands_file = '~/.config/rtx/shorthands.toml' # path to the shorthands file, see `RTX_SHORTHANDS_FILE`
disable_default_shorthands = false # disable the default shorthands, see `RTX_DISABLE_DEFAULT_SHORTHANDS`

[alias.nodejs]
my_custom_node = '18'  # makes `rtx install nodejs@my_custom_node` install node-18.x
                       # this can also be specified in a plugin (see below in "Aliases")

これらの設定は、 を使用して管理することもできます。

rtx settings ls|get|set|unset

環境変数

RTX は、環境変数を使用して構成することもできます。次のオプションを使用できます。

RTX_MISSING_RUNTIME_BEHAVIOR

これは、 の設定オプションと同じです。

missing_runtime_behavior
~/.config/rtx/config.toml

$ RTX_MISSING_RUNTIME_BEHAVIOR=ignore rtx install nodejs@18
$ RTX_NODEJS_VERSION=18 rtx exec -- node --version

RTX_DATA_DIR

これは、rtx がデータを格納するディレクトリです。デフォルトは です。

~/.local/share/rtx

RTX_CACHE_DIR

これは、rtx がキャッシュを格納するディレクトリです。デフォルトは Linux と macOS です。

~/.cache/rtx
~/Library/Caches/rtx

RTX_CONFIG_FILE

これは構成ファイルへのパスです。デフォルトは です。 (またはそれが設定されている場合)

~/.config/rtx/config.toml
$XDG_CONFIG_HOME/config.toml

RTX_DEFAULT_TOOL_VERSIONS_FILENAME

".tool-versions" 以外に設定すると、rtx は代替名を持つ構成を検索します。

RTX_${PLUGIN}_VERSION

ランタイムのバージョンを設定します。たとえば、に関係なく nodejs@18.x を使用します。 に設定されているものの。

RTX_NODEJS_VERSION=18
.tool-versions

RTX_LEGACY_VERSION_FILE

プラグインは、他のバージョンマネージャーが使用するバージョンファイルを読み取ることができます(プラグインによって有効になっている場合) たとえば、NodeJS の NVM の場合は .nvmrc です。

RTX_LOG_LEVEL=trace|debug|info|warn|error

、、およびも使用できます。これらはログを調整します 画面に出力します。

RTX_DEBUG=1
RTX_TRACE=1
RTX_QUIET=1

RTX_LOG_FILE=~/.rtx/rtx.log

ログをファイルに出力します。

RTX_LOG_FILE_LEVEL=trace|debug|info|warn|error

ログ ファイルの出力レベルと同じです。これは、必要な場合に便利です ログを保存しますが、ディスプレイに散らばらせないようにします。

RTX_LOG_LEVEL

RTX_VERBOSE=1

これは、 および 中のインストール出力を示しています。 これはおそらくマージされるはずなので、同じように動作します。 同じことのための2つの構成ですが、今のところそれはそれ自身の構成です。

rtx install
rtx plugin install
RTX_DEBUG=1

RTX_ASDF_COMPAT=1

asdf で使用できる出力ファイルのみ。

.tool-versions
rtx local|global

RTX_JOBS=1

並列にインストールするプラグインまたはランタイムの数を設定します。デフォルトは です。

4

RTX_SHORTHANDS_FILE=~/.config/rtx/shorthands.toml

短縮形のエイリアスにカスタムファイルを使用します。これは、プラグインを共有する場合に便利です 組織。

ファイルはtoml形式である必要があります。

elixir = "https://github.com/my-org/rtx-elixir.git"
nodejs = "https://github.com/my-org/rtx-nodejs.git"

RTX_DISABLE_DEFAULT_SHORTHANDS=1

プラグインをインストールするための短縮形のエイリアスを無効にします。次の場合は、完全なURLを指定する必要があります プラグインのインストール、例えば:

rtx plugin install nodejs https://github.com/asdf-vm/asdf-nodejs.git

現在、これにより以下が無効になります。

  • --fuzzy
    デフォルトの動作として(正確なバージョンを保存します)
    rtx local nodejs@18

RTX_HIDE_OUTDATED_BUILD=1

リリースが12か月前のものである場合、リリースされるたびに警告メッセージが表示されます。

rtx has not been updated in over a year. Please update to the latest version.

それがそれほど古い場合は、rtxを使用したくないでしょう。私は代わりにこれをやっています 自動更新。何らかの理由で古いバージョンを使い続けたい場合は、非表示にすることができます このメッセージは.

RTX_HIDE_OUTDATED_BUILD=1

エイリアス

RTX では、ランタイムのバージョンのエイリアスがサポートされています。このユースケースの18つは、LTSのエイリアスを定義することです。 ランタイムのバージョン。たとえば、nodejs@<>.x のバージョンとして指定できます。 したがって、ランタイムを in で使用できます。

lts/hydrogen
nodejs lts/hydrogen
.tool-versions

ユーザー エイリアスは、次のセクションを追加することで作成できます。

alias.<PLUGIN>
~/.config/rtx/config.toml

[alias.nodejs]
my_custom_18 = '18'

プラグインは、スクリプトを介してエイリアスを提供することもできます。ノードを示す例を次に示します.js バージョン:

bin/list-aliases

#!/usr/bin/env bash

echo "lts/hydrogen 18"
echo "lts/gallium 16"
echo "lts/fermium 14"

手記:

これは現在asdfで使用されていないrtx固有の機能であるため、どの機能にも含まれていない可能性があります プラグインは現在ありますが、プラグインの作成者は ASDF ユーザーに影響を与えることなくこのスクリプトを追加できます。

プラグイン

RTXは、内部でASDFのプラグインエコシステムを使用しています。これらのプラグインには、(インストール用)や(利用可能なすべてのバージョンを一覧表示するため)などのシェルスクリプトが含まれています。

bin/install
bin/list-all

組み込みプラグインの省略形のリストについては、https://github.com/asdf-vm/asdf-plugins を参照してください。独自のプラグインを作成する方法については、asdfのプラグインを作成するか、単に学ぶを参照してください それらがどのように機能するかについての詳細。

御意見・御感想

gitが追跡されていないファイルとしてファイルを表示するので、私は自分のプロジェクトにファイルを入れたくありません。
.tool-versions

gitにこれらのファイルを無視させるには、次の3つの方法があります。

  • プロジェクトのファイルに追加します。これには、無視するファイルに変更をコミットする必要があるという欠点があります。
    .tool-versions
    .gitignore
  • プロジェクトの .このファイルはプロジェクトに対してローカルであるため、コミットする必要はありません。
    .tool-versions
    .git/info/exclude
  • グローバル gitignore () に追加します。これにより、git はすべてのプロジェクトのファイルを無視します。必要に応じて、 を使用してプロジェクトに明示的に追加できます。
    .tool-versions
    core.excludesFile
    .tool-versions
    git add --force .tool-versions

独自のプラグインを作成するにはどうすればよいですか?

asdfのドキュメントに従ってください。すべてが同じように機能するはずです。 そうでない場合は、問題を開いてください。

RTX が失敗しているか、正しく機能していません

まず、設定またはを試してみて、それがあなたにより多くの情報を与えるかどうかを確認してください。 ログをファイルに書き込むように設定することもできます。

RTX_LOG_LEVEL=debug
RTX_LOG_LEVEL=trace
RTX_LOG_FILE=/path/to/logfile

アクティブ化フックで何かが発生している場合は、フックを無効にして手動で呼び出すことができます。 また、使用する環境変数を確認するために使用すると便利です。

eval "$(rtx hook-env)"
rtx env

最後に、コマンドがあります。あまり含まれていませんが、機能を追加したいと思います 問題のデバッグを支援するために。

rtx doctor

ウィンドウズのサポート?

これは私たちが追加したいものです!https://github.com/jdxcode/rtx/discussions/66

これは短期的な目標ではなく、プラグインの変更が必要になりますが、 それは実行可能であるべきです。

コマンド

rtx activate

Enables rtx to automatically modify runtimes when changing directory

This should go into your shell's rc file.
Otherwise, it will only take effect in the current session.
(e.g. ~/.bashrc)

Usage: activate [OPTIONS] [SHELL_TYPE]

Arguments:
  [SHELL_TYPE]
          Shell type to generate the script for
          
          [possible values: bash, fish, xonsh, zsh]

Options:
      --status
          Show "rtx: <PLUGIN>@<VERSION>" message when changing directories

Examples:
    $ eval "$(rtx activate bash)"
    $ eval "$(rtx activate zsh)"
    $ rtx activate fish | source
    $ execx($(rtx activate xonsh))

rtx alias get

Show an alias for a plugin

This is the contents of an alias.<PLUGIN> entry in ~/.config/rtx/config.toml

Usage: get <PLUGIN> <ALIAS>

Arguments:
  <PLUGIN>
          The plugin to show the alias for

  <ALIAS>
          The alias to show

Examples:
  $ rtx alias get nodejs lts/hydrogen
  18.0.0

rtx alias ls

List aliases
Shows the aliases that can be specified.
These can come from user config or from plugins in `bin/list-aliases`.

For user config, aliases are defined like the following in `~/.config/rtx/config.toml`:

  [alias.nodejs]
  lts = "18.0.0"

Usage: ls [OPTIONS]

Options:
  -p, --plugin <PLUGIN>
          Show aliases for <PLUGIN>

Examples:
  $ rtx aliases
  nodejs    lts/hydrogen   18.0.0

rtx alias set

Add/update an alias for a plugin

This modifies the contents of ~/.config/rtx/config.toml

Usage: set <PLUGIN> <ALIAS> <VALUE>

Arguments:
  <PLUGIN>
          The plugin to set the alias for

  <ALIAS>
          The alias to set

  <VALUE>
          The value to set the alias to

Examples:
  $ rtx alias set nodejs lts/hydrogen 18.0.0

rtx alias unset

Clears an alias for a plugin

This modifies the contents of ~/.config/rtx/config.toml

Usage: unset <PLUGIN> <ALIAS>

Arguments:
  <PLUGIN>
          The plugin to remove the alias from

  <ALIAS>
          The alias to remove

Examples:
  $ rtx alias unset nodejs lts/hydrogen

rtx bin-paths

List all the active runtime bin paths

Usage: bin-paths

rtx cache clear

Deletes all cache files in rtx

Usage: clear

rtx complete

Generate shell completions

Usage: complete --shell <SHELL>

Options:
  -s, --shell <SHELL>
          shell type
          
          [possible values: bash, elvish, fish, powershell, zsh]

Examples:
  $ rtx complete -s bash > /etc/bash_completion.d/rtx
  $ rtx complete -s zsh  > /usr/local/share/zsh/site-functions/_rtx
  $ rtx complete -s fish > ~/.config/fish/completions/rtx.fish

rtx current

Shows current active and installed runtime versions

This is similar to `rtx ls --current`, but this only shows the runtime
and/or version. It's designed to fit into scripts more easily.

Usage: current [PLUGIN]

Arguments:
  [PLUGIN]
          Plugin to show versions of
          
          e.g.: ruby, nodejs

Examples:
  # outputs `.tool-versions` compatible format
  $ rtx current
  python 3.11.0 3.10.0
  shfmt 3.6.0
  shellcheck 0.9.0
  nodejs 18.13.0

  $ rtx current nodejs
  18.13.0

  # can output multiple versions
  $ rtx current python
  3.11.0 3.10.0

rtx deactivate

Disable rtx for current shell session

This can be used to temporarily disable rtx in a shell session.

Usage: deactivate

Examples:
  $ rtx deactivate bash
  $ rtx deactivate zsh
  $ rtx deactivate fish
  $ execx($(rtx deactivate xonsh))

rtx direnv activate

Output direnv function to use rtx inside direnv

See https://github.com/jdxcode/rtx#direnv for more information

Because this generates the legacy files based on currently installed plugins,
you should run this command after installing new plugins. Otherwise
direnv may not know to update environment variables when legacy file versions change.

Usage: activate

Examples:
  $ rtx direnv activate > ~/.config/direnv/lib/use_rtx.sh
  $ echo 'use rtx' > .envrc
  $ direnv allow

rtx doctor

Check rtx installation for possible problems.

Usage: doctor

Examples:
  $ rtx doctor
  [WARN] plugin nodejs is not installed

rtx env

exports env vars to activate rtx in a single shell session

Use this if you don't want to permanently install rtx. It's not necessary to
use this if you have `rtx activate` in your shell rc file.
This can be used similarly to `asdf shell`. It requires `eval` to work since
it's not written in Bash.
It's also useful just to see what environment variables rtx sets.

Usage: env [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          Runtime version to use

Options:
  -s, --shell <SHELL>
          Shell type to generate environment variables for
          
          [possible values: bash, fish, xonsh, zsh]

Examples:
  $ eval "$(rtx env -s bash)"
  $ eval "$(rtx env -s zsh)"
  $ rtx env -s fish | source
  $ execx($(rtx env -s xonsh))

rtx exec

Execute a command with runtime(s) set

use this to avoid modifying the shell session or running ad-hoc commands with the rtx runtimes
set.

Runtimes will be loaded from .tool-versions, though they can be overridden with <RUNTIME> args
Note that only the plugin specified will be overridden, so if a `.tool-versions` file
includes "nodejs 18" but you run `rtx exec python@3.11`; it will still load nodejs@18.

The "--" separates runtimes from the commands to pass along to the subprocess.

Usage: exec [OPTIONS] [RUNTIME]... [-- <COMMAND>...]

Arguments:
  [RUNTIME]...
          Runtime(s) to start
          
          e.g.: nodejs@18 python@3.10

  [COMMAND]...
          Command string to execute (same as --command)

Options:
  -c, --command <C>
          Command string to execute

Examples:
  rtx exec nodejs@18 -- node ./app.js  # launch app.js using node-18.x
  rtx x nodejs@18 -- node ./app.js     # shorter alias

  # Specify command as a string:
  rtx exec nodejs@18 python@3.11 --command "node -v && python -V"

rtx global

Sets global .tool-versions to include a specified runtime

Displays the contents of ~/.tool-versions after writing.
The file is `$HOME/.tool-versions` by default.
Use `rtx local` to set a runtime version locally in the current directory.

Usage: global [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          Runtime(s) to add to .tool-versions
          
          e.g.: nodejs@18
          If this is a single runtime with no version, the current value of the global
          .tool-versions will be displayed

Options:
      --pin
          Save exact version to `~/.tool-versions`
          
          e.g.: `rtx local --pin nodejs@18` will save `nodejs 18.0.0` to ~/.tool-versions

      --fuzzy
          Save fuzzy version to `~/.tool-versions`
          
          e.g.: `rtx local --fuzzy nodejs@18` will save `nodejs 18` to ~/.tool-versions this is the default behavior unless RTX_ASDF_COMPAT=1

      --remove <PLUGIN>
          Remove the plugin(s) from ~/.tool-versions

Examples:
  # set the current version of nodejs to 18.x
  # will use a fuzzy version (e.g.: 18) in .tool-versions file
  $ rtx global --fuzzy nodejs@18

  # set the current version of nodejs to 18.x
  # will use a precise version (e.g.: 18.0.0) in .tool-versions file
  $ rtx global --pin nodejs@18

  # show the current version of nodejs in ~/.tool-versions
  $ rtx global nodejs
  18.0.0

rtx implode

Removes rtx CLI and all generated data

Skips config directory by default.

Usage: implode [OPTIONS]

Options:
      --config
          Also remove config directory

      --dry-run
          List directories that would be removed without actually removing them

rtx install

Install a runtime

This will install a runtime to `~/.local/share/rtx/installs/<PLUGIN>/<VERSION>`
It won't be used simply by being installed, however.
For that, you must set up a `.tool-version` file manually or with `rtx local/global`.
Or you can call a runtime explicitly with `rtx exec <PLUGIN>@<VERSION> -- <COMMAND>`.

Runtimes will be installed in parallel. To disable, set `--jobs=1` or `RTX_JOBS=1`

Usage: install [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          Runtime(s) to install
          
          e.g.: nodejs@18

Options:
  -p, --plugin <PLUGIN>
          Only install runtime(s) for <PLUGIN>

  -f, --force
          Force reinstall even if already installed

  -v, --verbose...
          Show installation output

Examples:
  $ rtx install nodejs@18.0.0  # install specific nodejs version
  $ rtx install nodejs@18      # install fuzzy nodejs version
  $ rtx install nodejs         # install version specified in .tool-versions
  $ rtx install                # installs all runtimes specified in .tool-versions for installed plugins
  $ rtx install --all          # installs all runtimes and all plugins

rtx latest

Get the latest runtime version of a plugin's runtimes

Usage: latest <RUNTIME>

Arguments:
  <RUNTIME>
          Runtime to get the latest version of

Examples:
  $ rtx latest nodejs@18  # get the latest version of nodejs 18
  18.0.0

  $ rtx latest nodejs     # get the latest stable version of nodejs
  20.0.0

rtx local

Sets .tool-versions to include a specific runtime

then displays the contents of .tool-versions
use this to set the runtime version when within a directory
use `rtx global` to set a runtime version globally

Usage: local [OPTIONS] [RUNTIME]...

Arguments:
  [RUNTIME]...
          Runtimes to add to .tool-versions
          
          e.g.: nodejs@18
          if this is a single runtime with no version,
          the current value of .tool-versions will be displayed

Options:
  -p, --parent
          Recurse up to find a .tool-versions file rather than using the current directory only
          by default this command will only set the runtime in the current directory ("$PWD/.tool-versions")

      --pin
          Save exact version to `.tool-versions`
          
          e.g.: `rtx local --pin nodejs@18` will save `nodejs 18.0.0` to .tool-versions

      --fuzzy
          Save fuzzy version to `.tool-versions`
          
          e.g.: `rtx local --fuzzy nodejs@18` will save `nodejs 18` to .tool-versions this is the default behavior unless RTX_ASDF_COMPAT=1

      --remove <PLUGIN>
          Remove the plugin(s) from .tool-versions

Examples:
  # set the current version of nodejs to 18.x for the current directory
  # will use a precise version (e.g.: 18.0.0) in .tool-versions file
  $ rtx local nodejs@18

  # set nodejs to 18.x for the current project (recurses up to find .tool-versions)
  $ rtx local -p nodejs@18

  # set the current version of nodejs to 18.x for the current directory
  # will use a fuzzy version (e.g.: 18) in .tool-versions file
  $ rtx local --fuzzy nodejs@18

  # removes nodejs from .tool-versions
  $ rtx local --remove=nodejs

  # show the current version of nodejs in .tool-versions
  $ rtx local nodejs
  18.0.0

rtx ls

List installed runtime versions

The "arrow (->)" indicates the runtime is installed, active, and will be used for running commands.
(Assuming `rtx activate` or `rtx env` is in use).

Usage: ls [OPTIONS]

Options:
  -p, --plugin <PLUGIN>
          Only show runtimes from [PLUGIN]

  -c, --current
          Only show runtimes currently specified in .tool-versions

Examples:
  $ rtx list
  -> nodejs     18.0.0 (set by ~/src/myapp/.tool-versions)
  -> python     3.11.0 (set by ~/.tool-versions)
     python     3.10.0

  $ rtx list --current
  -> nodejs     18.0.0 (set by ~/src/myapp/.tool-versions)
  -> python     3.11.0 (set by ~/.tool-versions)

rtx ls-remote

List runtime versions available for install

note that these versions are cached for commands like `rtx install nodejs@latest`
however _this_ command will always clear that cache and fetch the latest remote versions

Usage: ls-remote <PLUGIN> [PREFIX]

Arguments:
  <PLUGIN>
          Plugin to get versions for

  [PREFIX]
          The version prefix to use when querying the latest version same as the first argument after the "@"

Examples:
  $ rtx ls-remote nodejs
  18.0.0
  20.0.0

  $ rtx ls-remote nodejs@18
  18.0.0
  18.1.0

  $ rtx ls-remote nodejs 18
  18.0.0
  18.1.0

rtx plugins install

Install a plugin

note that rtx automatically can install plugins when you install a runtime
e.g.: `rtx install nodejs@18` will autoinstall the nodejs plugin

This behavior can be modified in ~/.rtx/config.toml

Usage: install [OPTIONS] [NAME] [GIT_URL]

Arguments:
  [NAME]
          The name of the plugin to install
          
          e.g.: nodejs, ruby

  [GIT_URL]
          The git url of the plugin
          
          e.g.: https://github.com/asdf-vm/asdf-nodejs.git

Options:
  -f, --force
          Reinstall even if plugin exists

  -a, --all
          Install all missing plugins
          
          This will only install plugins that have matching shorthands.
          i.e.: they don't need the full git repo url

  -v, --verbose...
          Show installation output

Examples:
  # install the nodejs plugin using the shorthand repo:
  # https://github.com/asdf-vm/asdf-plugins
  $ rtx install nodejs

  # install the nodejs plugin using the git url
  $ rtx install nodejs https://github.com/asdf-vm/asdf-nodejs.git

  # install the nodejs plugin using the git url only
  # (nodejs is inferred from the url)
  $ rtx install https://github.com/asdf-vm/asdf-nodejs.git

rtx plugins ls

List installed plugins

Can also show remotely available plugins to install.

Usage: ls [OPTIONS]

Options:
  -a, --all
          List all available remote plugins
          
          same as `rtx plugins ls-remote`

  -u, --urls
          Show the git url for each plugin
          
          e.g.: https://github.com/asdf-vm/asdf-nodejs.git

Examples:
  $ rtx plugins ls
  nodejs
  ruby

  $ rtx plugins ls --urls
  nodejs                        https://github.com/asdf-vm/asdf-nodejs.git
  ruby                          https://github.com/asdf-vm/asdf-ruby.git

rtx plugins ls-remote

List all available remote plugins

These are fetched from https://github.com/asdf-vm/asdf-plugins

Examples:
  $ rtx plugins ls-remote


Usage: ls-remote [OPTIONS]

Options:
  -u, --urls
          Show the git url for each plugin
          
          e.g.: https://github.com/asdf-vm/asdf-nodejs.git

rtx plugins uninstall

Removes a plugin

Usage: uninstall <PLUGIN>

Arguments:
  <PLUGIN>
          Plugin to remove

Examples:
  $ rtx uninstall nodejs

rtx plugins update

Updates a plugin to the latest version

note: this updates the plugin itself, not the runtime versions

Usage: update [OPTIONS] [PLUGIN]...

Arguments:
  [PLUGIN]...
          Plugin(s) to update

Options:
  -a, --all
          Update all plugins

Examples:
  $ rtx plugins update --all   # update all plugins
  $ rtx plugins update nodejs  # update only nodejs

rtx reshim

[experimental] rebuilds the shim farm

this requires that the shims_dir is set

Usage: reshim

Examples:
  $ rtx settings set experimental true
  $ rtx settings set shims_dir ~/.rtx/shims
  $ rtx reshim
  $ ~/.rtx/shims/node -v
  v18.0.0

rtx self-update

Updates rtx itself

Usage: self-update

rtx settings get

Show a current setting

This is the contents of a single entry in ~/.config/rtx/config.toml

Note that aliases are also stored in this file
but managed separately with `rtx aliases get`

Usage: get <KEY>

Arguments:
  <KEY>
          The setting to show

Examples:
  $ rtx settings get legacy_version_file
  true

rtx settings ls

Show current settings

This is the contents of ~/.config/rtx/config.toml

Note that aliases are also stored in this file
but managed separately with `rtx aliases`

Usage: ls

Examples:
  $ rtx settings
  legacy_version_file = false

rtx settings set

Add/update a setting

This modifies the contents of ~/.config/rtx/config.toml

Usage: set <KEY> <VALUE>

Arguments:
  <KEY>
          The setting to set

  <VALUE>
          The value to set

Examples:
  $ rtx settings set legacy_version_file true

rtx settings unset

Clears a setting

This modifies the contents of ~/.config/rtx/config.toml

Usage: unset <KEY>

Arguments:
  <KEY>
          The setting to remove

Examples:
  $ rtx settings unset legacy_version_file

rtx shell

sets a runtime for the current shell session

Only works in a session where rtx is already activated.

Usage: shell [RUNTIME]...

Arguments:
  [RUNTIME]...
          Runtime version(s) to use

Examples:
  $ rtx shell nodejs@18
  $ node -v
  v18.0.0

rtx uninstall

Removes runtime versions

Usage: uninstall <RUNTIME>...

Arguments:
  <RUNTIME>...
          Runtime(s) to remove

Examples:
  $ rtx uninstall nodejs@18.0.0 # will uninstall specific version
  $ rtx uninstall nodejs        # will uninstall current nodejs version

rtx version

Show rtx version

Usage: version

rtx where

Display the installation path for a runtime

Must be installed.

Usage: where <RUNTIME>

Arguments:
  <RUNTIME>
          runtime(s) to look up if "@<PREFIX>" is specified, it will show the latest installed version that matches the prefix otherwise, it will show the current, active installed version

Examples:
  # Show the latest installed version of nodejs
  # If it is is not installed, errors
  $ rtx where nodejs@18
  /Users/jdx/.local/share/rtx/installs/nodejs/18.0.0

  # Show the current, active install directory of nodejs
  # Errors if nodejs is not referenced in any .tool-version file
  $ rtx where nodejs
  /Users/jdx/.local/share/rtx/installs/nodejs/18.0.0

rtx which

shows the plugin that a bin points to

Usage: which <BIN_NAME>

Arguments:
  <BIN_NAME>
          

Examples:
  $ rtx which node
  /home/username/.local/share/rtx/installs/nodejs/18.0.0/bin/node

Comparison to asdf

rtx is mostly a clone of asdf, but there are notable areas where improvements have been made.

Performance

asdf made (what I consider) a poor design decision to use shims that go between a call to a runtime and the runtime itself. e.g.: when you call it will call an asdf shim file , which then calls , which then calls the correct version of node.

node
~/.asdf/shims/node
asdf exec

These shims have terrible performance, adding ~120ms to every runtime call. rtx does not use shims and instead updates so that it doesn't have any overhead when simply calling binaries. These shims are the main reason that I wrote this. Note that in the demo gif at the top of this README that isn't actually used when calling for this reason. The performance is identical to running node without using rtx.

PATH
rtx
node -v

I don't think it's possible for asdf to fix these issues. The author of asdf did a great writeup of performance problems. asdf is written in bash which certainly makes it challenging to be performant, however I think the real problem is the shim design. I don't think it's possible to fix that without a complete rewrite.

rtx does call an internal command every time the directory has changed, but because it's written in Rust, this is very quick—taking ~10ms on my machine. 4ms if there are no changes, 14ms if it's a full reload.

rtx hook-env

tl;dr: asdf adds overhead (~120ms) when calling a runtime, rtx adds a small amount of overhead (~10ms) when the prompt loads.

Environment variables

asdf only helps manage runtime executables. However, some tools are managed via environment variables (notably Java which switches via ). This isn't supported very well in asdf and requires a separate shell extension just to manage.

JAVA_HOME

However asdf plugins have a script that is used for exporting environment variables like

JAVA_HOME
. rtx simply exports the environment variables from the script in the plugin but places them in the shell for all commands. In asdf it only exports those commands when the shim is called. This means if you call it will set , but not if you call some Java tool like .
bin/exec-env
bin/exec-env
java
JAVA_HOME
mvn

This means we're just using the existing plugin script but because rtx doesn't use shims it can be used for more things. It would be trivial to make a plugin that exports arbitrary environment variables like dotenv or direnv.

UX

Some commands are the same in asdf but others have been changed. Everything that's possible in asdf should be possible in rtx but may use slightly different syntax. rtx has more forgiving commands, such as using fuzzy-matching, e.g.: . While in asdf you can run , you can't use in a file or many other places. In you can use fuzzy-matching everywhere.

rtx install nodejs@18
asdf install nodejs latest:18
latest:18
.tool-versions
rtx

asdf requires several steps to install a new runtime if the plugin isn't installed, e.g.:

$ asdf plugin add nodejs
$ asdf install nodejs latest:18
$ asdf local nodejs latest:18

In this can all be done in a single step to set the local runtime version. If the plugin and/or runtime needs to be installed it will prompt:

rtx

$ asdf local nodejs@18
rtx: Would you like to install nodejs@18.13.0? [Y/n] Y
Trying to update node-build... ok
Downloading node-v18.13.0-darwin-arm64.tar.gz...
-> https://nodejs.org/dist/v18.13.0/node-v18.13.0-darwin-arm64.tar.gz
Installing node-v18.13.0-darwin-arm64...
Installed node-v18.13.0-darwin-arm64 to /Users/jdx/.local/share/rtx/installs/nodejs/18.13.0
$ node -v
v18.13.0

I've found asdf to be particularly rigid and difficult to learn. It also made strange decisions like having but (why is one a flag and one a positional argument?). makes heavy use of aliases so you don't need to remember if it's or . If I can guess what you meant, then I'll try to get rtx to respond in the right way.

asdf list all
asdf latest --all
rtx
rtx plugin add nodejs
rtx plugin install nodejs

That said, there are a lot of great things about asdf. It's the best multi-runtime manager out there and I've really been impressed with the plugin system. Most of the design decisions the authors made were very good. I really just have 2 complaints: the shims and the fact it's written in Bash.

CI/CD

Using rtx in CI/CD is a great way to synchronize tool versions for dev/build.

GitHub Actions

Use

jdxcode/rtx-action
:

- uses: jdxcode/rtx-action@v1
- run: node -v # will be the node version from `.tool-versions`

Shims

While the PATH design of rtx works great in most cases, there are some situations where shims are preferable. One example is when calling rtx binaries from an IDE.

To support this, there is experimental support for using rtx in a "shim" mode. To use:

$ rtx settings set experimental true
$ rtx settings set shim_dir ~/.rtx/shims
$ rtx i nodejs@18.0.0
$ rtx reshim
$ ~/.rtx/shims/node -v
v18.0.0

direnv

direnv and rtx both manage environment variables based on directory. Because they both analyze the current environment variables before and after their respective "hook" commands are run, they can conflict with each other. As a result, there were a number of issues with direnv. However, we think we've mitigated these. If you find that rtx and direnv are not working well together, please comment on that ticket ideally with a good description of your directory layout so we can reproduce the problem.

If there are remaining issues, they're likely to do with the ordering of PATH. This means it would really only be a problem if you were trying to manage the same runtime with direnv and rtx. For example, you may use in an but also be maintaining a file with python in it as well.

layout python
.envrc
.tool-versions

A more typical usage of direnv would be to set some arbitrary environment variables, or add unrelated binaries to PATH. In these cases, rtx will not interfere with direnv.

As mentioned in the Quick Start, it is important to make sure that is called after in the shell rc file. rtx overrides some of the internal direnv state () so calling direnv first gives rtx the opportunity to make those changes to direnv's state.

rtx activate
direnv hook
DIRENV_DIFF

rtx inside of direnv ( in
use rtx
.envrc
)

If you do encounter issues with , or just want to use direnv in an alternate way, this is a simpler setup that's less likely to cause issues.

rtx activate

To do this, first use to build a function that you can use in files:

rtx
use_rtx
.envrc

$ rtx direnv activate > ~/.config/direnv/lib/use_rtx.sh

Now in your file add the following:

.envrc

use rtx

direnv will now call rtx to export its environment variables. You'll need to make sure to add to all projects that use rtx (or use direnv's to load it from a subdirectory). You can also add to .

use_rtx
source_up
use rtx
~/.config/direnv/direnvrc

Note that in this method direnv typically won't know to refresh files unless they're at the same level as a file. You'll likely always want to have a file next to your for this reason. To make this a little easier to manage, I encourage not actually using at all, and instead setting environment variables entirely in :

.tool-versions
.envrc
.envrc
.tool-versions
.tool-versions
.envrc

export RTX_NODEJS_VERSION=18.0.0
export RTX_PYTHON_VERSION=3.11

Of course if you use , then these steps won't have been necessary and you can use rtx as if direnv was not used.

rtx activate

Cache Behavior

rtx makes use of caching in many places in order to be efficient. The details about how long to keep cache for should eventually all be configurable. There may be gaps in the current behavior where things are hardcoded but I'm happy to add more settings to cover whatever config is needed.

Below I explain the behavior it uses around caching. If you're seeing behavior where things don't appear to be updating, this is a good place to start.

Plugin Cache

各プラグインには、に格納されているキャッシュがあります。それは格納します そのプラグインで利用可能なバージョンのリスト()、レガシーファイル名(下記参照)、 エイリアスのリスト、および各ランタイム・インストール内の bin ディレクトリー。

~/$RTX_CACHE_DIR/plugins/<PLUGIN>
rtx ls-remote <PLUGIN>

リモートバージョンは、デフォルトで毎日、または明示的に呼び出されるたびに更新されます。ファイルは ZLIBメッセージパックを表示したい場合は、以下を実行できます(msgpack-cliが必要です)。

rtx ls-remote

cat ~/$RTX_CACHE_DIR/nodejs/remote_versions.msgpack.zlib | perl -e 'use Compress::Raw::Zlib;my $d=new Compress::Raw::Zlib::Inflate();my $o;undef $/;$d->inflate(<>,$o);print $o;' | msgpack-cli decode

レガシーファイルキャッシュ

有効にすると、rtx は asdf-nodejs などのレガシーファイル名を読み取ります。これにより、2か所のキャッシュが活用されます。 プラグインは呼び出されます:

.node-version

  • リスト-レガシー-ファイル名私が見たすべてのプラグインでは、これは単に ".nvmrc .node-version"のようなファイル名の静的リストを返します。 これは、デフォルトで毎日更新される標準の「ランタイム」キャッシュと一緒にキャッシュされます。
  • 解析-レガシー-ファイルこのプラグインバイナリは、レガシーファイルを解析してバージョンを取得するために呼び出されます。それは比較的です コストが高いため、レガシーファイルとして解析されるすべてのファイルがにキャッシュされます。 ファイルが変更されるまでキャッシュされたままになります。これは、へのパスを持つ単純なテキストファイルです。 ファイル名のハッシュとして保存されたレガシーファイル。
    ~/.local/share/rtx/legacy_cache

発達

でテストを実行します。

just

$ just test

コードベースを次のようにリントします。

$ just lint-fix