RVM finding system gems' executables

后端 未结 3 1438
囚心锁ツ
囚心锁ツ 2021-02-15 19:04

I have installed RVM along with ruby versions. However if I fire up the console and run the command rails server, bundle install, etc. I get this error

bash: /us         


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-15 19:08

    Explanation of rubygems bin folders and PATH

    Oh. You didn't have rails installed in your rvm ruby, but you did in your system ruby.

    Individual gems, like rails can have a bin directory that will contain executable helper scripts. Your system default rubygems is making symlinks from your system /usr/bin/ dir into the gem's bin folder for these helper executables.

    RVM provides a similar facility, except instead of polluting the system /usr/bin dir, it just appends its ~/.rvm/gems/#{rvm_gemset_string}/bin folder to the PATH environment variable.


    Importing system Rubygems list into your new rvm rubies' gem directories

    RVM by default will not import your gems from your system ruby installation into your rvm ruby installs. It makes a full clean fork of the entire ruby system including rubygems (the gem 'rubygems') and rubygems' gem list. When you rvm install 1.9.2 it's like you've made a completely new install of everything used with ruby.

    If you'd like to get all your system ruby gems that you were previously using into your preferred rvm ruby, try this:

      rvm use system
      rvm gemset export system.gems
      rvm use 1.9.2
      rvm gemset import system.gems
      #You'll now have all your system gems reinstalled to your new ruby version
    

    Original Answer/ Edits from @Telemachus

    Try moving the lines that source rvm to the end of your ~/.bash_profile or ~/.bashrc (whichever you have it in):

    '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function'
    

    .

    bash: /usr/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file ...
    |                 |                 ^--------------------------------\
    ^ Bash, not rvm;  ^/usr/bin/rails, not ~/.rvm/gems/*/bin/rails;      |
                           Some ruby leftover from a previous install in the os
    

    You have rails installed in /usr/bin, which is probably before the rvm ruby bin path in your bash echo $PATH variable, so it's finding the system rails install (/usr/bin/rails, a ruby script) which starts like this:

    #! /usr/bin/ruby18

    You've gotta make the conflict stop happening, the best of all possible ways is making sure that RVM's bin dir is at the beginning of your PATH. This happens in the #Load rvm environment script that you added to your ~/.bash_profile when installing rvm. If you installed rvm as a system library rather than just for your user, this will be different.

    If you get to that case, ask @Telemachus.

    You'll then need to ensure you've gotten the rails gem installed in your new rvm ruby as above.

    Acceptance Test:

    You'll find that when you've done rvm use 1.9.2, then which ruby will return something like ~/.rvm/rubies/1.9.2/bin/ruby, and which rails should return something like ~/.rvm/gems/*/bin/rails.

提交回复
热议问题