LoginSignup
2
0

More than 3 years have passed since last update.

[Ruby][rbenv] 特定のバージョンのアンインストールを禁止する

Last updated at Posted at 2019-06-14

方法

rbenv hooks という機能を使う。

以下、rbenv は ~/.rbenv にインストールしていることを想定する。

まず ~/.rbenv/rbenv.duninstall という名前のディレクトリを作る。そして、そのディレクトリに .bash という拡張子で任意の名前のファイルを作成する。

$ mkdir ~/.rbenv/rbenv.d/uninstall
$ vim ~/.rbenv/rbenv.d/uninstall/prevent_uninstall.bash

作成した .bash ファイルの内容は次の通り。

~/.rbenv/rbenv.d/uninstall/prevent_uninstall.bash
#!/usr/bin/env bash

VERSIONS=(2.5.5 2.6.3)
SCRIPT=$(cat <<EOS
if [[ " ${VERSIONS[*]} " == *" $@ "* ]]; then
  echo "Ruby $@ はアンインストールできません。アンインストールしたい場合は $BASH_SOURCE を削除してください。"
  exit 1
fi
EOS
)

before_uninstall "$SCRIPT"

この状態で Ruby 2.6.3 をアンインストールしようとしてもできない。

$ rbenv uninstall 2.6.3
rbenv: remove /Users/quanon/.rbenv/versions/2.6.3? [yN] y
Ruby 2.6.3 はアンインストールできません。アンインストールしたい場合は /Users/quanon/.rbenv/rbenv.d/uninstall/prevent_uninstall.bash を削除してください。

参考

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