How do I change my Ruby version using RVM?

2019-01-10 00:56发布

问题:

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.9.3-p0

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

回答1:

Fixed it. I needed to add:

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

to .zshrc



回答2:

This happened to me too. I had:

export PATH=~/.rvm/bin:$PATH

Added in my .bashrc.

All I had to do was add another

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

to the same file and it worked! Of course, you have to restart your terminal after that.



回答3:

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)



回答4:

(Kubuntu 11.10) The ~/.bash_profile is now called ~/.profile

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.profile
source ~/.profile
rvm info # And now the fields display


回答5:

To Change the Default Version of ruby:

In Ubuntu 11.10
please change your GNOME terminal setting :

Go to Terminal and then follow the following instructions:

1.  Edit > Profile Preferences
2.  Open Title and Command Tab               
3.  Check Run Command as a login Shell 
4.  Restart terminal

Run this command on terminal:

rvm --default use ruby_Version


回答6:

To add all RVM functionality to your .bash_profile you should use following command:

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

After that you should reload the current shell or open a new terminal session and type the following command to reload .bash_profile:

source .bash_profile


回答7:

The above solution will only work, if RVM is installed for the current user. A more general solution would use the RVM path variable:

# The following code loads RVM as user or system install:
[[ -s "$rvm_path/scripts/rvm" ]] && . "$rvm_path/scripts/rvm"


回答8:

I just had to invoke source ~/.bash_profile



回答9:

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.



回答10:

Installing RVM, See here http://octopress.org/docs/setup/rvm/



回答11:

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.



回答12:

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.



回答13:

You need to change your terminal emulator preferences to allow login shell. Sometimes it is required to use /bin/bash --login as the command.



标签: ruby rvm