LoginSignup
6
5

More than 5 years have passed since last update.

anyenvユーザが設定すべきrbenv.elの設定

Posted at

今日になってrbenv.elを知って、以下のような設定ファイルを書いていた。

(require 'rbenv)
(global-rbenv-mode)
(setq rbenv-installation-dir "~/.anyenv/envs/rbenv")

anyenvでrbenvをインストールしているのだからこれでいいだろ。
と思ってたんだが、実はこれだとダメ。
M-x rbenv-useなどをやってみるとわかるけど、~/.rbenvをハナから見に行っているくさい。

rbenv.elには以下のように記載されている

(defcustom rbenv-installation-dir (or (getenv "RBENV_ROOT")
                                      (concat (getenv "HOME") "/.rbenv/"))

なんでかなーと思って調べてみたら、こんな記事を見つけた。

どうやらこれに該当しているぽいので、以下のように設定を書き換えてみた

(require 'rbenv)
(global-rbenv-mode)
(custom-set-variables '(rbenv-installation-dir "~/.anyenv/envs/rbenv"))

一見うまくいったかに見えたが、これも動作しない。
rbenv.elの中身をよくよくみると

(defcustom rbenv-installation-dir (or (getenv "RBENV_ROOT")
                                      (concat (getenv "HOME") "/.rbenv/"))
  "The path to the directory where rbenv was installed."
  :group 'rbenv
  :type 'directory)

となっており、ここをcustom-set-variablesで設定できはするのだが

(defun rbenv--expand-path (&rest segments)
  (let ((path (mapconcat 'identity segments "/"))
        (installation-dir (replace-regexp-in-string "/$" "" rbenv-installation-dir)))
    (expand-file-name (concat installation-dir "/" path))))

ここでセットされるrbenv-installation-dirは初期値である ~/.rbenv/になってしまっている。
すっごい考えたのだが、elisp弱者の私は結局以下の方法で解決させた。

(setenv "RBENV_ROOT" "~/.anyenv/envs/rbenv")
(require 'rbenv)
(global-rbenv-mode)

負けた感じがする。

6
5
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
6
5