rbenv and bundler: "bad interpreter: No such file or directory"

13,230

Solution 1

The fact that gem is being executed by your /usr/local/bin means that rbenv isn't in your $PATH correctly.

Step 1:

Please delete any references you have of rbenv in the following areas:

  • ~/.profile
  • ~/.bashrc
  • ~/.bash_profile
  • ~/.gemrc

Step 2:

Reinstall rbenv using these instructions. It won't override, it will simply update changes to your ~/.bash_profile. Once reinstalled close your terminal and reopen. Everything should work correctly at that time.

Step 3:

Verify that everything was installed correctly by executing cat ~/.bash_profile. You should see the following. If you do, you're good to go.

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

Many cudos to @theTinMan for recently helping me sort through my rbenv installation.

Solution 2

Find the bundle executable (in a non project directory - default system ruby) and delete it:

which bundle

rm <path_obtained_above>

Now go to your project directory, or switch to your ruby version and install bundler:

gem install bundler

Then execute rbenv rehash

and now try executing bundle install and it should work. You will need to do this once for each ruby version installed.

Share:
13,230

Related videos on Youtube

Badr Tazi
Author by

Badr Tazi

Updated on June 03, 2022

Comments

  • Badr Tazi
    Badr Tazi almost 2 years

    I messed up my configuration. I am running Ubuntu 14.04 and had some issues when I tried to move from a project to an other. I tried to uninstall and reinstall rbenv and then installed Ruby 2.1.7 following this guide: https://gorails.com/setup/ubuntu/14.04.

    Now, when I run gem install bundler nothing happens and I can't install any gems. When I type bundler or bundler -v I see this:

    /usr/local/bin/bundler: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
    

    I spent many hours trying to solve this but I really don't know what to do.

    • PJP
      PJP over 8 years
      Rule one: Be VERY careful following instructions on websites describing how to install anything. There is no garbage collection on the internet, so old, outdated, or simply bad, information can sit around, polluting people's minds about how to do things. Go to the authors and maintainers for installation instructions as they know better than anyone how to install their code.
  • PJP
    PJP over 8 years
    If the instructions for installing rbenv are followed, step #2 isn't needed. The script will do it correctly automatically.
  • binarymason
    binarymason over 8 years
    @theTinMan, thanks. I updated answer for anyone's future reference.
  • tmarthal
    tmarthal over 7 years
    This is what worked for me. The rbenv rehash function found the proper bundle executable.
  • Leonel
    Leonel almost 7 years
    On WSL, bundle was trying to use ruby.exe from Windows!!! All I had to do was rbenv rehash. Thank you!
  • Frederic Adda
    Frederic Adda almost 7 years
    I don't understand step 1. Could you please explain?
  • sebkkom
    sebkkom about 3 years
    @FrédéricAdda He means that you should delete any lines that mention rbenv in one of those 4 files (as well as ~/.zshrc, if you are using it instead).