rubybundlerrbenv

rbenv - Ruby - How to switch ruby versions between multiple projects


I installed Ruby using rbenv. I am using Mac. For one of my project I am using ruby 2.6.3. For my other project I need ruby 2.7.4. So I installed both the versions.

In my first project, if I do rbenv versions, it correctly shows

   system
   * 2.6.3 (set by /Users/suganyas/academics/project1/.ruby-version)
    2.7.4

For my second project, i set ruby version 2.7.4 using the command

rbenv local 2.7.4

So if I do rbenv versions from my second project, it again shows,

  system
  2.6.3
  * 2.7.4 (set by /Users/suganyas/project2/ceep/.ruby-version)

But when I do bundle install, I am getting the following error

  Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4

Full trace is here

    The git source `git://github.com/sqlninja/outdatedbrowser_rails.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
   The git source `git://github.com/nhodges/phantomjs-gem.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
    The git source `git://github.com/heapsource/active_model_otp.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
  Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4

Kindly help me what am I doing wrong.


Solution

  • Running the below commands helped me in choosing the correct rbenv local versions

    echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
    source ~/.bash_profile