Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make rbenv recognise '1.9.3-p***' Ruby versions?

Tags:

ruby

rbenv

I'm trying to get some Ruby project running and the project is using .ruby-version file. That file contains only:

1.9.3

I installed the latest Ruby 1.9.3:

$ rbenv install 1.9.3-p448

However when I ran ruby --version I got

rbenv: version '1.9.3' is not installed

To fix this error I listed ~/.rbenv/versions/ and it contained the folder 1.9.3-p448. I renamed that folder to 1.9.3 and ran rbenv rehash. This fixed the problem.

Looks like the -p448 part (What does it mean? Patch?) confuses rbenv. How can I make it recognise the correct 1.9.3 version without manually renaming the folder in ~/.rbenv? I could also change .ruby-version to 1.9.3-p448, but that means that the project will depend on my particular "patch" of Ruby 1.9.3, which is bad.

like image 975
Nikita Avatar asked Sep 05 '13 11:09

Nikita


People also ask

How do I install a specific version of Rbenv Ruby?

To install and use a different version of Ruby, run the rbenv commands with a different version number, such as rbenv install 2.3. 0 and rbenv global 2.3. 0 . You now have one version of Ruby installed and have set your default Ruby version.

How do I use a specific version of Ruby?

Set Ruby version with rvm on MacTo set a default Ruby version with rvm, enter rvm --default use 3.0. 0 on the command line. To switch to the system ruby, enter rvm use system . To switch back to the default, rvm default .


1 Answers

rbenv doesn't allow this. From the wiki:

Other version managers might allow fuzzy version matching on the string read from .ruby-version file, e.g. they might allow "1.9.3" (without patch suffix) to match the latest Ruby 1.9.3 release. rbenv will not support this, because such behavior is unpredictable and therefore harmful.

mislav's comment from A Common .ruby-version File For Ruby Projects:

rbenv is going to support .ruby-version, but definitely without any fuzzy matching. Here's why I think fuzzy matching is a bad idea:

  1. Let's suppose I have 1.9.3-p0 installed.
  2. I put "ruby-1.9" to .ruby-version in my project and all is well.
  3. After some time I install 1.9.3-p300 to try it out and suddenly all my projects marked with "ruby-1.9" automatically upgrade to it. Gems need to be reinstalled, native extensions need to be upgraded, etc. Nightmare.

One of the important reasons why we have version managers is to be precise about versions. rbenv is going to be precise. If you want cute shortcuts & aliases, you can always make symlinks.

Alternatives

  • Override the .ruby-version file by setting the RBENV_VERSION environment variable (e.g. for the current shell by running rbenv shell 1.9.3-p448).
  • Symlink 1.9.3 to 1.9.3-p448, see rbenv-aliases for details.
like image 169
Stefan Avatar answered Sep 19 '22 14:09

Stefan