.zshenv:2: command not found: rbenv - ruby

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.

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.

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

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.

Related

command not found: rbenv when starting a new terminal

I have this line eval "$(rbenv init - zsh)" in my .zshrc. But it's throwing the command not found error for rbenv every time I start a new terminal. But rbenv works if I type it in manually, it only breaks when I start a new terminal. So in order for me to set a specific version for ruby, I need to run eval "$(rbenv init - zsh)" manually every time instead of relying on the terminal itself to run it automatically.
PS: I installed rbenv with Homebrew.
I have this line eval "$(rbenv init - zsh)" in my .zshrc.
The line should be after the rbenv binary location is loaded to the PATH environment variable.
Example:
export PATH="/home/someusername/.rbenv/bin:$PATH"
eval "$(rbenv init - zsh)"

rbenv: no such command `init-'

I'm trying to install ruby in terminal via homebrew.
So far I've entered:
brew install rbenv
and then I rain
rbenv init
after the command was run I received
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
finally I entered:
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
I restarted my terminal per instructions and then received
rbenv: no such command `init-'
at the top of my new terminal.
error messages: rbenv: no such command `init-'
expected messages: nothing, blank terminal
The default shell (Bash before macOS 10.15) on macOS is a login shell. Only .bash_profile is used in initialization by default.
You need to put eval "$(rbenv init -)" into ~/.bash_profile but not ~/.bashrc.
Bash init files
login mode:
/etc/profile
~/.bash_profile, ~/.bash_login, ~/.profile (only first one that exists)
interactive non-login:
/etc/bash.bashrc (some Linux; not on Mac OS X)
~/.bashrc
non-interactive:
source file in $BASH_ENV
Check the path of the red line for an interactive, login shell on macOS.
References
Unix shell initialization
Shell startup scripts

rbenv command not found on Mac OS

We are trying to run rbenv on El-Capitan 10.11.6. When we try to run rbenv command in the terminal we got the following error message:
command not found
We googled how to solve that issue and one possible solution is to add the "rbenv" to the system PATH, we followed the steps stated in this link. When we run the "$PATH" to check whether or not the rbenv path was added properly into the system PATH, we got the the same result:
command not found
The result of "$PATH" command is:
qwe-Mac-mini:~ amrbakri$ rbenv
-bash: rbenv: command not found
qwe-Mac-mini:~ asd$ echo $PATH
/Users/asd/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin
Can you please tell me how to add the path of rbenv properly? And what did I do wrong in the previous steps so that I can fix it.
rbenv isn't a normal command if you've installed it correctly:
$ type rbenv
rbenv is a function
. . .
According to Homebrew on Mac OS X:
You'll only ever have to run rbenv init once.
That's a bit misleading because the result of running the command is:
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
So you need to manually add eval "$(rbenv init -)" to some file that bash will source on startup. For most people ~/.bash_profile is the right place.
I notice the commands you listed seem to be run from two different users: amrbakri and asd. Combined with the question's use of "we", I wonder if there might be a problem with the environment being set correctly for one user, but not the other. Can you try using just one user?
If you are running from a non-interactive shell (such as in a crontab), you might need to add eval "$(rbenv init -)" to the startup script.
I following the instructions about "bash" command, then do the "eval" operation.
I'm in MacOS 11.2.3, in your .bash_profile, add the two lines.
export PATH="$HOME/.rbenv/bin:$PATH"#this is the required step for my mac
eval "$(rbenv init -)"
refer: https://github.com/rbenv/rbenv#homebrew-on-mac-os-x

How to correct my $PATH?

I use Mac OS X and i have some profile and bash_profile. Here are the contents of my file :
cat ~/.profile
PATH=/usr/local/git/bin:$PATH
export PATH
and
cat ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export M2_HOME=/Users/myName/Tools/apache-maven-3.2.5
export GIT_HOME=/usr/local/git
export PATH=$PATH:$M2_HOME/bin:$GIT_HOME/bin
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
### ADDED FOR SUBLIME SYMLINK
export PATH=/usr/bin/local/bin:$PATH
Here is the content of $PATH :
echo $PATH
/usr/bin/local/bin:/Users/myname/.rbenv/shims:/Users/myname/.rbenv/shims:/usr/local/heroku/bin:/usr/local/git/bin:/usr/local/git/bin:/usr/local/git/bin:/Users/myname/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-3.4.0/lib/rspec.rb:/usr/bin/local/bin:/Users/myname/.rbenv/shims:/Users/myname/.rbenv/shims:/usr/local/heroku/bin:/usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/ImageMagick/bin:/Users/myname/Tools/apache-maven-3.2.5/bin:/usr/local/git/bin:/usr/local/mysql/bin:/Users/myname/Tools/apache-maven-3.2.5/bin:/usr/local/git/bin:/usr/local/mysql/bin
I don't understand why i have this /Users/myname/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-3.4.0/lib/rspec.rb in the path. How i could remove it ? I cannot see it neither in ~/.profile nor in ~/.bash_profile.
Thanks for your help
That's a binstub for RSpec being set by rbenv.
use rbenv rehash to make sure your .rbenv/versions/... folder is current
Make sure you're using ruby 2.2.2 via rbenv by running rbenv shell 2.2.2
gem uninstall -a rspec
rbenv rehash
Reload shell.
You should only have one of this line:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
You've also got a ton of duplication in your $PATH it's likely your bashrc files are being loaded multiple times, or that you're running another RC script you're not aware of:
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/shims
/Users/myname/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-3.4.0/lib/rspec.rb
/Users/myname/Tools/apache-maven-3.2.5/bin
/Users/myname/Tools/apache-maven-3.2.5/bin
/bin
/opt/ImageMagick/bin
/sbin
/usr/bin
/usr/bin/local/bin
/usr/bin/local/bin
/usr/local/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/git/bin
/usr/local/heroku/bin
/usr/local/heroku/bin
/usr/local/mysql/bin
/usr/local/mysql/bin
/usr/sbin
See also:
https://github.com/rbenv/rbenv/wiki/Understanding-binstubs
http://dan.carley.co/blog/2012/02/07/rbenv-and-bundler/

rbenv shell not command

rbenv installed. but rbenv shell not command.
ationtekiMacBook-Air:~ dation$ rbenv versions
system
* 2.0.0-p247 (set by /Users/dation/.ruby-version)
dationtekiMacBook-Air:~ dation$ rbenv version
2.0.0-p247 (set by /Users/dation/.ruby-version)
dationtekiMacBook-Air:~ dation$ rbenv shell
rbenv: no such command `shell'
ationtekiMacBook-Air:~ dation$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
There is this note in rbenv's README (see Installation) about the shell command:
Note that you'll need rbenv's shell integration enabled (step 3 of the installation instructions) in order to use this command.
Step 3 is:
Add rbenv init to your shell to enable shims and autocompletion.
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Same as in previous step, use ~/.profile on Ubuntu, ~/.zshrc for Zsh.
Did you follow that instruction?
one gotya that I haven't seen posted on the internet is that in .bash_profile, you have ensure that
export PATH="$HOME/.rbenv/bin:$PATH"
is placed before
eval "$(rbenv init -)"
Otherwise the shell will try to run rbenv init before it can be found.
Reversing these two lines will cause both problems described by the OP;
ruby -v not showing the version that was set by rbenv
rbvenv shell returning "rbenv: no such command `shell’".
Don't ask how I know!
I today opened an issue in Github to propose an update to sstephenson's already awesome documentation.

Resources