From the rbenv README:
Understanding PATH
When you run a command like
rubyorrake, your operating system searches through a list of directories to find an executable file with that name. This list of directories lives in an environment variable calledPATH, with each directory in the list separated by a colon:/usr/local/bin:/usr/bin:/binDirectories in
PATHare searched from left to right, so a matching executable in a directory at the beginning of the list takes precedence over another one at the end. In this example, the/usr/local/bindirectory will be searched first, then/usr/bin, then/bin.Understanding Shims
rbenvworks by inserting a directory of shims at the front of your PATH:~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
Check where you have added ~/.rbenv/shims to the PATH (probably in a file like ~/.bashrc, or ~/.zshrc?), and ensure you are adding it to the START of the PATH, not the end.
To see the full contents of the $PATH variable, you can run:
echo $PATH
Answer from Tom Lord on Stack OverflowFrom the rbenv README:
Understanding PATH
When you run a command like
rubyorrake, your operating system searches through a list of directories to find an executable file with that name. This list of directories lives in an environment variable calledPATH, with each directory in the list separated by a colon:/usr/local/bin:/usr/bin:/binDirectories in
PATHare searched from left to right, so a matching executable in a directory at the beginning of the list takes precedence over another one at the end. In this example, the/usr/local/bindirectory will be searched first, then/usr/bin, then/bin.Understanding Shims
rbenvworks by inserting a directory of shims at the front of your PATH:~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
Check where you have added ~/.rbenv/shims to the PATH (probably in a file like ~/.bashrc, or ~/.zshrc?), and ensure you are adding it to the START of the PATH, not the end.
To see the full contents of the $PATH variable, you can run:
echo $PATH
Simplified instructions for MacOS users:
sudo vim ~/.zshrc
Add this at the end of file:
eval "$(rbenv init - zsh)"
Write and Quit vim editor
:wq
Verify setup:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Expected output:
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20220910.1)
Counting installed Ruby versions: none
There aren't any Ruby versions installed under `/Users/username/.rbenv/versions'.
You can install Ruby versions like so: rbenv install 3.1.2
Checking RubyGems settings: OK
Auditing installed plugins: OK
Checking for rbenv shims in PATH: found at wrong position
Troubles with rbenv, manjaro, and shims in PATH - Help - The Odin Project
rbenv, what am I doing in wrong in here?
'which rails' could give some enlightment. Maybe it's an alias on your configuration? or maybe it is installed as a system gem, and you need to install rails once again for 3.0.6
also, try 'bundle exec rails server' instead
More on reddit.comruby - Rbenv not rehashing correctly and making shims - Stack Overflow
I like ruby, and rails as well. but sometimes it's so frustrating.What am I doing wrong in here?
eval "$(rbenv init - zsh)" export PATH="$HOME/.rbenv/shims:$PATH"
I already have this on .zshrc file.
'which rails' could give some enlightment. Maybe it's an alias on your configuration? or maybe it is installed as a system gem, and you need to install rails once again for 3.0.6
also, try 'bundle exec rails server' instead
This is why I insist on using Docker. I know what to expect, and I can reset my Docker environment to the original state any time I want to. This isn't the case when you rely on your host environment as your development environment. Not being able to reset my development environment willy-nilly is a deal breaker for me.
I don't know how you got rbenv to end up in /bin/rbenv and usr/bin/rbenv, but for what I can see from their installation guide you only need ~/.rbenv/bin/rbenv.
Assuming you use bash, I think these are all added to your $PATH in ~/.bashrc. You should find something like:
export PATH="$PATH:/bin/rbenv"
And
export PATH="$PATH:/usr/bin/rbenv"
You can remove those lines. To clean up properly you can also remove the rbenv installs they refer to as well.
Lastly, as the error message says, you want to run rbenv init after doing this to create the shims folder.
I did not have export PATH="$PATH:/bin/rbenv" and export PATH="$PATH:/usr/bin/rbenv" in my ~/.bashrc
I just ran
sudo apt-get purge ruby
sudo apt-get purge rbenv
and then
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
showed only one path.
Complete setup commands for rbenv in linux machines Initial setup
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
~/.rbenv/bin/rbenv init
check whether eval "$(rbenv init -)" is present in ~/.bashrc. If not present run the following command
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Then,
source ~/.bashrc
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
source ~/.bashrc
rbenv rehash
Now, rbenv installed. Now install your ruby version ( change the version below to your version). And set that to global version. (Use latest stable version as global as it is a good practice. You can set local versions differently depending on your working project)
rbenv install 2.5.1
rbenv global 2.5.1
Finished.
So, it turns out I figured it out myself.
What I was missing (rbenv doctor helped me) was to have shims in my PATH. Adding
eval "$(rbenv init -)"
did the trick.