Geoffrey Lord
Geoffrey Lord

Reputation: 21

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]

Upvotes: 2

Views: 2555

Answers (2)

mislav
mislav

Reputation: 15209

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:

  1. rbenv() shell function gets called;
  2. the function executes rbenv sh-shell 2.0;
  3. sh-shell outputs export RBENV_VERSION=2.0;
  4. 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).

Upvotes: 4

oylenshpeegul
oylenshpeegul

Reputation: 3424

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

Upvotes: 0

Related Questions