Search code examples
rubyzshrbenvzshrc

.zshenv:2: command not found: rbenv


When switching from bash to zsh, I looked up how to resolve an issue with my rbenv folder not being used correctly by zsh and found this:

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL

I ran all of these and seem to be using the correct rbenv folder now, but I get this error message whenever I open a new iTerm window:

/Users/myname/.zshenv:2: command not found: rbenv

What am I doing wrong? Any help would be very appreciated.


Solution

  • You need to add two things to your PATH. First rbenv itself and second the ruby shims.

    Part 1 rbenv

    Installation

    Homebrew

    If you installed rbenv with brew, then the rbenv executable should be linked to /usr/local/bin/rbenv.

    See homebrew installation documentation for details.

    Please add /usr/local/bin to your path PATH, if it is missing.

    # in ~/.zshrc
    
    export PATH=/usr/local/bin:$PATH
    

    Github Checkout

    If you install rbenv via a Github checkout, then the rbenv executalbe should be stored in ~/.rbenv/bin.

    See github installation documentation for details.

    Please add ~/.rbenv/bin to your path PATH, if it is missing.

    # in ~/.zshrc
    
    export PATH=$HOME/.rbenv/bin:$PATH
    

    Verfiy

    Please verify that rbenv is in your path by calling which rbenv. The installation path should be returend.

    Part 2 shims

    Add the ruby shims to you path.

    # in ~/.zshrc
    
    eval "$(rbenv init -)"
    

    Instead of the eval "$(rbenv init -)" command you can also add the shims folder directly.

    # in ~/.zshrc
    
    export RBENV_ROOT=$HOME/.rbenv
    export PATH=$RBENV_ROOT/shims:/versions:$PATH
    

    Part 3 rbenv doctor

    You might also run the rbenv-doctor script mentioned here, to check your installation.