0

I am trying to use a specific version of ruby on a particular project. I looked into the RVM and rbenv packages, but had little success with any of them.

These are the steps I took:

  • create project directory and navigate to it;

  • run rbenv install 2.3.1; after navigating to ~/.rbenv/versions I can see a "2.3.1" in there;

  • running "rbenv local" also echos 2.3.1;

My Gemfile is as follows:

ruby '2.3.1'

source 'https://rubygems.org/' do 
    gem 'test-kitchen'
    gem 'kitchen-terraform'
end

However, when I run bundle install i get the following error:

Your Ruby version is 2.5.1, but your Gemfile specified 2.3.1

Its my first time working with Ruby, so I am struggling a little. I appreciate all help, and can provide more details if required.

Rafael Marques
  • 1,335
  • 4
  • 22
  • 35
  • 1
    Your machine might be using system-ruby -- look at this: https://stackoverflow.com/questions/18549107/which-ruby-version-am-i-really-running – z atef Oct 19 '18 at 14:25
  • Thank you for this link. It helped me uninstall the main ruby installation, and install it using rvm, which finally fixed the error. I guess I can install the most recent version with rvm again, and use both versions as I seam fit. Cheers mate. – Rafael Marques Oct 19 '18 at 14:40
  • > Its my first time working with Ruby Not 100% clear, but if you're coming from a different language, you might also consider `asdf` or `anyenv` to manage Rubies since they have plugins for several other languages as well. Then, you can manage versions of multiple languages all at once – David Bodow Oct 19 '18 at 20:06

2 Answers2

2

If you store the ruby version of your project in .ruby-version and the gemset (i.e. gem list workspace) in .ruby-gemset of your project (which I recommend doing if the specific version is important to you), rvm should pick this up when you cd into your project directory. Sometimes it doesn't however depending on your setup or installation, in which case you can choose them explicitly with:

rvm use `cat .ruby-version`
rvm gemset use `cat .ruby-gemset

which I add to any installation scripts for example. You may need to run gem install bundler before running bundle install the first time you use the new gemset.

NGinEar45
  • 109
  • 5
0

Set your default rbenv version like this:

$ rbenv shell jruby-1.7.1

See in: https://github.com/rbenv/rbenv#rbenv-shell