11

I'm on Linux Mint 17.2. I recently removed ruby with apt-get purge ruby.

I then installed rbenv and then did rbenv install 2.3.0 so now, ~/.rbenv/versions/2.3.0/bin/ruby exists.

But now, I can't do gem install rubocop. I get this:

$ gem install rubocop
rbenv: gem: command not found

The `gem' command exists in these Ruby versions:
  2.3.0

But I can do ~/.rbenv/versions/2.3.0/bin/gem install rubocop. However, once I'm done, I can't use it:

$ rubocop --auto-correct
-bash: /usr/local/bin/rubocop: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory

I also can't find out where this ruby came from:

$ dpkg -S /usr/bin/ruby1.9.1
dpkg-query: no path found matching pattern /usr/bin/ruby1.9.1

It's possible it was installed via RVM a long time ago.

Any idea how I can fix my Ruby?

Makoto
  • 104,088
  • 27
  • 192
  • 230
Housni
  • 963
  • 1
  • 10
  • 23

2 Answers2

31

try run rbenv global 2.3.0 && rbenv rehash

Mike Belyakov
  • 1,355
  • 1
  • 13
  • 24
  • 1
    Thanks Mike. This worked for me. Can you provide an explanation for your answer please? I'd like to know what I did wrong. – Housni Mar 21 '16 at 19:25
  • 4
    You should select ruby version before using, and you only install it, but did not selected. And also, after major operations `rbenv rehash` to update rbenv status – Mike Belyakov Mar 22 '16 at 00:46
  • As I understand it, everytime you install a gem that builds native code you have to run rbenv rehash to update the shell magic to that new gem. This is something that can trip you up a bunch if you forget about it. – Andy D Apr 09 '16 at 20:53
  • 3
    @MikeBelyakov your comment should have been pat of the answer as it describes the essence of the command. – Zeeng Jan 17 '20 at 12:05
  • This answer solved my issue and the comments describe it really good. Thank you. – Sang Dang Sep 26 '21 at 18:05
10

It looks like you haven't run the rbenv shell magic to add bin shims to your path.

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

It's recommended to add that to your .bashrc or .bash_profile so it gets executed on login.

Take a read through this - it covers rbenv and bundler but the initial setup will be what you need to look at.

mcfinnigan
  • 11,442
  • 35
  • 28
  • This is what I initially thought too but I have the required content in my rc files. I even sourced them a few times to make sure the required paths were in $PATH. Mikes solution worked for me though. Thanks for taking the time to reply though! – Housni Mar 21 '16 at 19:24
  • Glad you got it sorted :) – mcfinnigan Mar 21 '16 at 19:59
  • `if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi` is safer for the eval line. – voidstate May 15 '17 at 07:57