How do I change my Ruby version using RVM?

前端 未结 13 1120
我寻月下人不归
我寻月下人不归 2020-12-02 04:49

I am not able to switch the current Ruby version:

➜  ~  rvm list

rvm rubies

   ruby-1.9.2-p290 [ x86_64 ]
   ruby-1.9.3-p0 [ x86_64 ]

➜  ~  rvm use ruby-1         


        
相关标签:
13条回答
  • 2020-12-02 05:27

    On a clean install of Ubuntu 12.04 I ran into the same issue. The RVM installer creates or appends to a file called ~/.bash_login the necessary bit of code to avoid the original problem:

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
    

    However this does not seem to get invoked. Adding it to ~/.bashrc resolved the issue for me.

    0 讨论(0)
  • 2020-12-02 05:27

    In my case on Ubuntu, the entry in ~/.bashrc had:

     [[ -s "$HOME/.rvm/scripts/rvm" ]] && ."$HOME/.rvm/scripts/rvm" # BAD
    

    instead of:

     [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # WORKING
    

    Notice the missing space between . and "$HOME.

    Also, if this is the problem, you should also be noticing an error on top when you start your terminal.

    0 讨论(0)
  • 2020-12-02 05:27

    I had a global install of RVM, which runs /etc/profile.d/rvm.sh. However, that script requires the BASH_VERSION or ZSH_VERSION to be set. I was running from crontab, which uses "sh".

    I created a wrapper script that uses /bin/bash to source /etc/profile.d/rvm.sh.

    0 讨论(0)
  • 2020-12-02 05:29

    I just had to invoke source ~/.bash_profile

    0 讨论(0)
  • 2020-12-02 05:31

    Fixed it. I needed to add:

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM 
    

    to .zshrc

    0 讨论(0)
  • 2020-12-02 05:35

    Your shell doesn't know about the RVM function. After you install it, it tells you how to take care of this. Or go to the install page on the RVM site and check out the section titled "2. Load RVM into your shell sessions as a function"

    Run this once to add the line that loads rvm into your ~/.bash_profile:

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

    or manually add it yourself. (Note that on some systems, you will want to put it in other places, for example on my system, Mac OSX Lion, I put it in ~/.profile)

    0 讨论(0)
提交回复
热议问题