rbenv: Either documentation or installer fails to setup shims directory correctly

I have setup rbenv according to the documentation on a fresh CentOS 7.7 machine. The result is that the installation does not work (ruby is not found regardless of me adding it as local or global). I finally found out that the shims directory never makes it to the path and therefore executed

echo 'export PATH="$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile

which made the stuff work. I am unsure whether the installer or rbenv init should do this or the documentation is lacking this step.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Hello, I am just posting this here so that someone else can see it and maybe help me? It might also be something that other people are experiencing…

I appended eval "$(rbenv init -)" into my ~/.zshrc and my shims are not being prepended to my $PATH.

Here is what I get when I run rbenv init -

export PATH="/Users/ayylmao/.rbenv/shims:${PATH}"
export RBENV_SHELL=zsh
source '/usr/local/Cellar/rbenv/1.1.2/libexec/../completions/rbenv.zsh'
command rbenv rehash 2>/dev/null
rbenv() {
  local command
  command="${1:-}"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "$(rbenv "sh-$command" "$@")";;
  *)
    command rbenv "$command" "$@";;
  esac
}

But when I run which ruby I just get /usr/bin/ruby.


Will it be necessary to add to my shell config something similar to the user who opened this thread, export PATH="$HOME/.rbenv/shims:$PATH ?

I am wondering if I should go nuclear and uninstall / reinstall…

I was stuck in a similar situation on macOS 14.2 with M2, attempting to install rbenv. I would get no shims from which ruby but saw the shims in my path. This comment was able to get me unstuck! Posting here for future hapless devs

I added these lines at the end of my .zshrc file (for those of us who are using oh my zsh)

eval "$(rbenv init -)" export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"

# Load rbenv automatically by appending
# the following to ~/.zshrc:
eval "$(rbenv init - zsh)"

@jpeters-ml Have you followed these instructions and added the “eval” line to your zshrc?

eval "$(rbenv init - zsh)"

After that and restarting your shell or terminal window, your PATH should be:

/Users/<user>/.rbenv/shims:/usr/local/sbin: ...

Hi mislav,

thanks for your explanations. I looked into it and I think I now got the problem (which is probably the cause for several issues I stumbled over while troubleshooting that have users complaining about rbenv init not working). I believe the documentation is misleading at best for users having no experience with rbenv and just want to use it.

First, from your explanation and from the installation guide, I would assume that rbenv init updates the path such that ruby is working, i.e. it includes the shims directory.

Second, I remember the output of rbenv init that you quoted and I still think this can only be interpreted as adding this line to ~/.bash_profile is optional, i. e. if I do not want to load rbenv automatically, I do not need to do that, but I can call rbenv init on demand.

However, calling rbenv init on demand does not work, and I believe I have now understood why: If I add the eval line into my ~/.bash_profile, the stuff is sourced in the shell, whereas if I just call rbenv init, it is not. The following ouput from a CentOS 7.7 machine illustrates this effect:

[root@crabcore ~]# rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

[root@crabcore ~]# which ruby
/usr/bin/which: no ruby in (/root/.nodenv/bin:/root/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@crabcore ~]# eval "$(rbenv init -)"
[root@crabcore ~]# which ruby
/root/.rbenv/shims/ruby

I would therefore suggest hinting users at calling eval "$(rbenv init -)" and not rbenv init if they want to use rbenv on demand and/or change the output of rbenv init telling users that they must add the eval line.

Best regards, Christoph