Rails not using correct version of Ruby

后端 未结 9 2287
春和景丽
春和景丽 2021-02-14 15:20

New information

This is what happens with rails console:

Loading development environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 &         


        
相关标签:
9条回答
  • 2021-02-14 15:50

    Most likely Culprit:

    Check your PATH environment variable by typing printenv PATH in the shell -- /usr/bin might come before wherever RVM installs it's Rubies -- but you don't want that when using RVM!!

    If /usr/bin comes before the RVM-location, when checking for programs, it will take /usr/bin/ruby -- the Ruby which came with your LINUX (most likely 1.8.7) -- not the RVM default ruby (which is 1.9.2)

    You can double check this like this by asking your system which ruby:

    which ruby                           # this should be an RVM path! , not /usr/bin
    ruby --version                       # you want this to be 1.9.2
    /usr/bin/ruby --version              # the old system default Ruby is most likely 1.8.7
    
    ~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
    ~/.rvm/rubies/default/bin/ruby --version
    

    Check your PATH environment variable -- make sure that the directory where your RVM ruby version is installed comes FIRST, before /usr/bin

    e.g. in my PATH, the ~/.rvm/... comes first, then /usr/local/bin, then /usr/bin (with a couple of other dirs of course)


    as mentioned before, rvm --default use 1.9.2 , so you get the default Ruby version in any new shell.

    Looks like you have installed RVM system-wide under /usr/local.

    IMHO system-wide installation can be a mess when upgrading gems, and it can cause a couple of problems going forward.

    I would not recommend doing that! I had a longer email discussion with Wayne Seguin, and even he uses local user RVM for his environments.

    Check the RVM docu - it says there: Please note that Single-User supercedes Multi-User [...RVM installation].

    That means that if you have installed RVM system-wide, and you also (accidentially?) installed it for a user account, then for that user, the locally installed RVM takes precedence. This is an extra pit-fall which is easy to avoid by not installing system-wide in the first place :)

    Personally, I would uninstall the system-wide RVM and install it only for the relevant user(s), who can then more easily install their gems themselves without interfering with other users.

    Finally: when installing local to the user account, make sure that you install your gems specifically for the correct Ruby version, and that you do not use sudo to install the gems!

    hopes this helps! good luck!


    EDIT

    If you're getting different output from RUBY_VERSION than your irb or rails console prompt, then there must be something amiss with the way Ruby was compiled / installed. This looks more and more like you need to re-install RVM and your Ruby version 1.9.2, but first check your PATH, to make sure that's not the culprit.


    A Sanity Check, to check if there is interference from your LINUX installation:

    create a new user account, do a new RVM install for that user and install Ruby 1.9.2 -- then try if it works in that account, or if it shows the same problems.

    0 讨论(0)
  • 2021-02-14 15:52

    Man, I was having this exact problem and the way I solved it was by reinstalling bundler. It seems that bundler was caching the RUBY_VERSION to 1.8.7.

    I'm not using rvm, I had to use this to set the default ruby version:

    sudo update-alternatives --config ruby
    sudo update-alternatives --config gem
    

    And then, I reinstalled bundler and it worked!

    Hopefully you can solve it with this approach

    0 讨论(0)
  • 2021-02-14 15:59

    Do you have a .rvmrc file in your user directory?

    $ cat ~/.rvmrc
    => export rvm_path="/home/nick/.rvm"
    

    It should look something like that?

    And also check you've set up a .bashrc file like this:

    echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc 
    
    0 讨论(0)
提交回复
热议问题