rbenv shell not command - ruby

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.

Related

How to switch Ruby versions on macOS using rbenv

I read a few Stack Overflow posts on a similar question, however, I cannot seem to fix my issue.
How do I get ruby --version to match the rbenv version?
rbenv version
2.6.5 (set by /Users/user/rubyonrails/lists/.ruby-version)
ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
When I run
rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
I read a few other questions on Stack Overflow and modified my bash_profile accordingly, however it has not remedied the faulty rbenv init command.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export PROJECT_HOME=$HOME/Django
source /usr/local/bin/virtualenvwrapper.sh
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/bin:$PATH"
Only add these lines on your .bashrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
later use this command $ rbenv install version-ruby
and for switch use $ rbenv global version-ruby
(replace version-ruby for the number of the version.)

.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.
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.

Changing Ruby versions with rbenv from system and "shell" command does not work

I can change my rbenv superficially with local and global commands but my Ruby version does not fundamentally change. My shell command is not recognized but local and global are. I had RVM previously but uninstalled (as far as I know). What should I do?
$ rbenv versions
system
* 1.9.3-p0 (set by /Users/geoffreylord/.rbenv/version)
2.0.0-p247
$ rbenv local
rbenv: no local version configured for this directory
$ rbenv global
1.9.3-p0
$ rbenv shell
rbenv: no such command `shell'
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
The reason rbenv's shell command is called rbenv-sh-shell on disk is because shell is a special type of command whose output is to be eval'ed in the current interactive shell of the user. This makes it possible for this command to change environment variables in the shell, which is not otherwise possible by simply executing a command.
In order for rbenv-sh-* commands to work, rbenv does a little hack by defining the rbenv() shell function which executes all rbenv commands normally and eval's the output of sh-* commands. So what happens when you run rbenv shell 2.0 is:
rbenv() shell function gets called;
the function executes rbenv sh-shell 2.0;
sh-shell outputs export RBENV_VERSION=2.0;
rbenv() function eval's that in your current interactive shell.
The rbenv() function is installed by the eval "$(rbenv init -)" part of the rbenv setup process. (You should have that line in your .bashrc or similar init script.) This init step is optional (rbenv will work without it) but it does give you tab-completion for rbenv as well as enables rbenv shell functionality as described here, as well as any other sh-* command that might exists (e.g. those provided by plugins).
Oops! Looks like somebody stuttered.
$ ls $HOME/.rbenv/libexec/*shell*
/home/tim/.rbenv/libexec/rbenv-sh-shell
Looks like there is no shell command, but rather a sh-shell command
$ rbenv sh-shell
rbenv: no shell-specific version configured
Yup. Let's see, if we link to it with a rbenv-shell
$ cd $HOME/.rbenv/libexec/
$ ln -s rbenv-sh-shell rbenv-shell
then we should get a working shell command
$ rbenv shell
rbenv: no shell-specific version configured

How can I use the correct rbenv Ruby version with Emacs' shell-command?

Here is my current setup:
MacBook with Mountain Lion
Emacs is http://emacsformacosx.com/
rbenv with global 1.9.3-p374
Login shell is zsh
My ~/.zprofile (I am certain that the file gets executed):
# Customize to your needs...
export PATH=/Users/username/.rbenv/shims:/Users/username/.nvm/v0.9.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
eval "$(rbenv init -)"
I want to use my globally defined ruby version with M-x shell-command (or M-!). I expect M-! ruby -v to return ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.3.0] but I get ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0].
If I run ruby -v in M-x shell the correct version is loaded. I suspect that M-! does not work as expected as it runs as a non interactive shell.
Is there a way to fix this, besides running something like: M-! eval "$(rbenv init -)" && ruby -v? This works, but I do not want to insert eval "$(rbenv init -)" && infront of everything I execute.
Your path from shell needs to be seen by Emacs, and to make that easier, use the following elisp package.
https://github.com/purcell/exec-path-from-shell
You can install this through el-get or manually by dropping it in your ~/.emacs.d/lisp directory and adding this to your ~/.emacs or ~/.emacs.d/init.el file.
(add-to-list 'load-path "~/.emacs.d/lisp")
(unless (require 'exec-path-from-shell nil 'noerror)
(exec-path-from-shell-initialize))
The lisp file will take care of the rest.

Ruby versions differ in Terminal & bash

In Terminal, ruby -v gives me:
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
But if I type /bin/bash then ruby -v I get:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
I suspect this is something to do with my PATH config(s). My $PATH variable is different in both the above environments. There are other issues e.g. rvm won't run unless I go into bash mode.
For info, my ~/.bashrc contains:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Looks like "login shell" is not enabled, you need to enable it in Terminal Emulator Preferences, sometimes it is needed to use /bin/bash --login.
There are also known issues with ZSH, but it seams to be unrelated.
Try which ruby from "terminal" and "/bin/bash". Your 1.9.3 is inside your ~/.rvm path.
Type rvm info. You should get a list of the settings for RVM.
In your ~/.bashrc OR ~/.bash_profile, you should have RVM's initialization code. If you don't you didn't install RVM completely and need to finish. Read all the instructions on the RVM installation page.
This was not due to a $PATH problem. What I've learned is that RVM cannot be run unless you change your default login shell to either Bash or ZSH. Just firing up Terminal in Mac won't work. You make the global change to using Bash like this:
chsh -s /bin/bash
(swap /bin/bash for whatever your bash path is, find out using which bash).
The RVM website does say that bash>=3.2.25 is a prerequisite, but doesn't say what that is or how to check whether you have it. It also advises you to run rvm requirements to check what you need - and you can't run this unless you change your shell (all quite confusing for somebody new to this).
Thanks to the replies above for getting me there in the end.
See also: Bad: modifier error when installing RVM

Resources