Rbenv: -bash: /usr/local/bin/rails: /usr/local/opt/ruby/bin/ruby: bad interpreter: No such file or directory

Created on 22 Mar 2016  路  4Comments  路  Source: rbenv/rbenv

I tried to set up my Rails Dev Env.
I was not successful.
These are the results:

command: $ xcode-select version returns: 2343.
command: $ rbenv version returns: rbenv 1.0.0
command: $ rbenv global 2.2.1 set rbenv to *2.2.1
command: $ ruby -v returns: 2.2.1p85
Okay so far...

command: $ gem install rails returned: Successfully installed rails-4.2.6
command: $ rbenv rehash after every command
command: $ rails new testapp returns: -bash: /usr/local/bin/rails: /usr/local/opt/ruby/bin/ruby: bad interpreter: No such file or directory
I think I have a problem.

command: $ git --version returns: git version 2.5.4
What might be going on and can I recover from such a fall?

When I start the server and look at the url I see versions of rail there.

command: $ gem server
at the url localhost:8808 I see 3 gems versions of rails there: 4.2.4, 4.2.5, 4.2.6

How do I resolve this?

I've posted on the Stack Overflow, but I haven't found a successful solution.

I need help.

Most helpful comment

@sonnybrakes Read up on your shell (probably Bash since you're on OS X) and how it uses PATH.

The PATH is set up in your shell's initialization scripts (.bash_profile on OS X), so if you want to _remove_ something, you update your .bash_profile to simply _not add_ it in the first place.

Looks like you have duplicate PATH entries for rbenv shims dir as well, which suggests that you're somehow doing rbenv init twice.

Review your .bashrc for lines like this:

export PATH="/usr/local/bin:$PATH"

Odds are, you're putting /usr/local/bin at the head of your PATH _after_ initializing rbenv.

That's why invoking rails is finding the executable in /usr/local/bin/ instead of in /Users/michelfrechette/.rbenv/shims/.

Your executable at /usr/local/bin/rails is due to an old gem install from a Ruby you had/have installed at /usr/local/opt/ruby鈥攖hat's Homebrew's Ruby path. Advise uninstalling that.

All 4 comments

This is the output when I run $ echo $PATH
Michels-MacBook-Pro:~ michelfrechette$ echo $PATH
/usr/local/bin:/Users/michelfrechette/.rbenv/shims:/Users/michelfrechette/.rbenv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/usr/local/heroku/bin:/Users/michelfrechette/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/9.4/bin
Michels-MacBook-Pro:~ michelfrechette$

You mixed another ruby interpreter located /usr/local/opt/ruby/bin/ruby and rbenv installation. Can you try to remove first /usr/local/bin from $PATH variable.

How do I do that?

@sonnybrakes Read up on your shell (probably Bash since you're on OS X) and how it uses PATH.

The PATH is set up in your shell's initialization scripts (.bash_profile on OS X), so if you want to _remove_ something, you update your .bash_profile to simply _not add_ it in the first place.

Looks like you have duplicate PATH entries for rbenv shims dir as well, which suggests that you're somehow doing rbenv init twice.

Review your .bashrc for lines like this:

export PATH="/usr/local/bin:$PATH"

Odds are, you're putting /usr/local/bin at the head of your PATH _after_ initializing rbenv.

That's why invoking rails is finding the executable in /usr/local/bin/ instead of in /Users/michelfrechette/.rbenv/shims/.

Your executable at /usr/local/bin/rails is due to an old gem install from a Ruby you had/have installed at /usr/local/opt/ruby鈥攖hat's Homebrew's Ruby path. Advise uninstalling that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HuckyDucky picture HuckyDucky  路  4Comments

aaalveee picture aaalveee  路  4Comments

alankis picture alankis  路  5Comments

maayannaveh picture maayannaveh  路  4Comments

vennsoh picture vennsoh  路  4Comments