rbenv-communal-gems
rbenv-communal-gems copied to clipboard
Installing via homebrew breaks communal-gem-home command
When installed via homebrew, running rbenv communal-gem-home gives the following error:
/usr/local/bin/../version_cache/2.3.4
mkdir: /usr/local/bin/../version_cache: Permission denied
/usr/local/bin/rbenv-communal-gem-home: line 22: /usr/local/bin/../version_cache/2.3.4: No such file or directory
Because homebrew uses symlinks, the cachedir is set to "${BASH_SOURCE%/*}/../version_cache", which evaluates to /usr/local/bin/../version_cache. To fix this, I replaced this line https://github.com/tpope/rbenv-communal-gems/blob/master/bin/rbenv-communal-gem-home#L14 with:
cachedir=$(dirname `php -r "echo realpath(\"$BASH_SOURCE\");"`)/../version_cache
I have the same problem, I brew install rbenv-communal-gems and got:
$ bundle --version
mkdir: /usr/local/bin/../version_cache: Permission denied
/usr/local/bin/rbenv-communal-gem-home: line 21: /usr/local/bin/../version_cache/2.4.2: No such file or directory
Bundler version 1.15.4
Even using readlink or realpath gives a pretty undesirable path within the homebrew keg's bin directory:
/usr/local/Cellar/rbenv-communal-gems/1.0.1/bin/rbenv-communal-gem-home/../version_cache
I prefer to use a directory within $RBENV_ROOT, which seems like the right place to be keeping mutable state:
cachedir="$RBENV_ROOT/.communal-gem-version-cache"
Which gives, for me:
/usr/local/rbenv/.communal-gems-version-cache
Or, for per-user:
/Users/sj26/.rbenv/.communal-gems-version-cache
Seems easier than trying to figure out xdg cache directories or something, too.
I can confirm this error with the plugin installed from homebrew.
Rbenv ships with it's own realpath we could use. I agree, the cache location is weird. I don't remember why I did it that way.