Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fall back to other binary in PATH if gem-installed binary not installed in current ruby #187

Open
gerrit opened this Issue · 20 comments
@gerrit

I‘ve got a binary (installed by npm) in /usr/local/bin/lessc that I would like to use some of the time. But for some Ruby projects I‘m using the LESS gem which installs a binary in ~/.rbenv/shims/lessc.

~/.rbenv/shims is before /usr/local/bin in my PATH.

I’d like to be able to use the gem-provided binary when I‘m using a ruby version where it is installed, and otherwise (default case for me) fall back to /usr/local/bin/lessc.

Currently, I get the message

`rbenv: lessc: command not found

The lessc' command exists in these Ruby versions:
1.9.2-p290

and the only way to use the npm-provided binary by specifying the whole path. It seems to me that the shim binary should fall back to other binaries that are in the PATH already if nothing is installed in the current ruby.

@zol

I second this motion. I'm having the same problem after having installed the heroku toolbelt, and having the heroku gem installed in one of my ruby versions.

Whilst the message telling me that the command exists in another version can be helpful, in this case it's preventing me from calling the correct binary.

@mislav
Collaborator

I definitely agree; unfortunately I have no ideas how to approach solving this issue. This requires group thinking /cc @sstephenson @sheerun

@sstephenson
Owner

Ref. #276.

@sheerun

Add ~/.rbenv/defaults with command - ruby version map?

@mrak

pyenv by @yyuu, which is a python version handler based off of rbenv already has this fallback functionality. Perhaps take a look at his project?

Check the pyenv global section of his README.md about pushing/popping versions of python

@yyuu

The current master of pyenv is based on rbenv 0.4.0, all you here will feel very familiar to the code :)

Yep, pyenv can fallback to secondary (or tertiary, or more) versions to look up specified command. The significant changes are in pyenv-which.

I created my patch for rbenv-which as issue187 to allow looking up commands outside from rbenv. If it seems fine, I'd like to send it new pull request.

@yyuu

I created the modification to the rbenv-which as a plugin rbenv-which-ext. This plugin allows rbenv to find commands not installed in rbenv.

Also, I discarded the issue187 branch because it corrupts the tests of rbenv.

@ianheggie

Thanks yyuu, the plugin rbenv-which-ext fixed a problem I had with vagrant as a system binary, but having a clone of a project that includes vagrant as a gem and thus triggers a shim.

Can this be considered for inclusion into rbenv itself after all the plugin callbacks have executed?

@CpuID

+1 for this feature, I just created a patch from yyuu@975f4dc and applied it locally and it ticked the boxes for my use.

@benwoodward

+1 Having the same issue with heroku-toolbelt

@mislav
Collaborator

@benwoodward and others: If you have a problem with vagrant or heroku commands, use rbenv whence to find which Ruby versions have installed gems for those projects, uninstall those gems and rbenv rehash.

Vagrant and Heroku toolbelt have a runtime environment that is supposed to be isolated from the Rubies and gems installed for development. This concept is ruined if you have vagrant or heroku gems installed anywhere, so you'd best uninstall them.

@royzinn

Please excuse me if it's the wrong issue, but I did what @mislav suggested and uninstalled heroku from all rubies (after rbenv whence).
I then installed the heroku-toolbelt and I keep getting the error: 'rbenv: heroku: command not found'
I also tried manually installing the heroku gem but getting other errors.

When doing which heroku I get '/Users/royzinn/.rbenv/shims/heroku'

Is there any suggestion on how to make the heroku command live again? (BTW - it all started after installing new ruby version and trying to run the heroku command on it, it worked fine for previous ruby versions)

Thanks,
Roy

@benwoodward

@royzinn I had exactly the same issue. Installing @yyuu's https://github.com/yyuu/rbenv-which-ext fixed it for me.

@royzinn

Thanks a lot @benwoodward I will give it a try.
I actually did something which worked and I hope it didn't break anything else, so I would love to hear thoughts on this. I symlinked heroku into rbenv/shims/heroku and it seems to be working, is it a good approach?

@mislav
Collaborator

@royzinn Did you rbenv rehash after you uninstalled heroku gem from every version? That should get rid of /Users/royzinn/.rbenv/shims/heroku

@royzinn

@mislav - yes I did. But just to be on the safe side,I did hat in the local ruby version (rbenv local) I was at.
Still after doing that, when I ran the 'which heroku' command it was showing the one under rbenv/shims
I had to remove the folder manually and them symlinked

@mislav
Collaborator

Symlinking heroku into rbenv/shims/heroku will work for a short while but will get rewritten the next time something runs rbenv rehash, so you can't count on it as a permanent solution.

If you did rbenv rehash, and the heroku shim is still in rbenv, that means that some Ruby version still has the Heroku gem. Please run this in your shell:

for ver in $(rbenv whence heroku); do RBENV_VERSION="$ver" gem uninstall -a -x heroku; done
rbenv rehash
@fwuensche

@mislav's last comment worked like a charm for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.