.zshenv:2: command not found: rbenv
Asked Answered
H

4

10

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.

Hustler answered 17/11, 2019 at 0:11 Comment(4)
Try removing rbenv and reinstalling from scratch.Guinness
You shouldn't need the last line; .zshenv is sourced automatically before .zshrc is.Chitwood
Are you sure rbenv is, in fact, in $HOME/.rbenv/bin?Chitwood
@Hustler did any of the comments or my answer help you? Can you please give us feedback or accept the answer?Sulfonal
S
14

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.

Sulfonal answered 17/12, 2019 at 23:12 Comment(1)
Funnily enough, I skipped straight to the brew doctor script curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash and it identified the one thing I had missed, saving a lot of timeAdena
P
4

I had this same error. I could run which rbenv and rbenv just fine, but no matter what I would get command not found: rbenv. The issue was that I had eval "$(rbenv init -)" in my ~/.zshenv and not my ~/.zshrc file. You may still have the path to rbenv be added to $PATH within ~/.zshenv for it to work.

Playpen answered 16/12, 2020 at 7:30 Comment(0)
S
3

I had the same problem... when I ran ruby or rbenv, I got this error "command not found"

try this:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv

echo 'eval "$(rbenv init - zsh)"' >> ~/.zshenv

echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.zshenv
Strander answered 13/8, 2020 at 13:22 Comment(0)
M
0

This is because you added the commands in .zshenv file.

Follow the steps below on your terminal.

  1. run code ~/.zshenv
  2. remove the rbenv code in zshenv file
  3. run source ~/.zshenv
  4. reopen terminal
Mort answered 15/6 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.