如何使用 RVM 更改我的 Ruby 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8663936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change my Ruby version using RVM?
提问by donald
I am not able to switch the current Ruby version:
我无法切换当前的 Ruby 版本:
? ~ 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.
回答by donald
Fixed it. I needed to add:
修复。我需要添加:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM
to .zshrc
到 .zshrc
回答by The Mitra Boy
This happened to me too. I had:
这也发生在我身上。我有:
export PATH=~/.rvm/bin:$PATH
Added in my .bashrc.
添加在我的 .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.
到同一个文件,它起作用了!当然,您必须在此之后重新启动终端。
回答by Joshua Cheek
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 installpage on the RVM site and check out the section titled "2. Load RVM into your shell sessions as a function"
你的 shell 不知道 RVM 函数。安装后,它会告诉您如何处理此问题。或者转到RVM 站点上的安装页面并查看标题为“2. 将 RVM 作为函数加载到 shell 会话中”的部分
Run this once to add the line that loads rvm into your ~/.bash_profile:
运行一次以将加载 rvm 的行添加到您的 ~/.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)
或者自己手动添加。(注意,在某些系统上,你会想把它放在其他地方,例如在我的系统 Mac OSX Lion 上,我把它放在 ~/.profile 中)
回答by Lindsay
(Kubuntu 11.10) The ~/.bash_profileis now called ~/.profile
(Kubuntu 11.10) ~/.bash_profile现在被称为~/.profile
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.profile
source ~/.profile
rvm info # And now the fields display
回答by Mayank Raipure
To Change the Default Version of ruby:
更改 ruby 的默认版本:
In Ubuntu 11.10
please change your GNOME terminal setting :
在 Ubuntu 11.10 中,
请更改您的 GNOME 终端设置:
Go to Terminaland 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
回答by Недоброе Привидение
To add all RVM functionality to your .bash_profile you should use following command:
要将所有 RVM 功能添加到您的 .bash_profile,您应该使用以下命令:
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:
之后,您应该重新加载当前 shell 或打开一个新的终端会话并键入以下命令以重新加载 .bash_profile:
source .bash_profile
回答by user2408574
The above solution will only work, if RVM is installed for the current user. A more general solution would use the RVM path variable:
仅当为当前用户安装了 RVM 时,上述解决方案才有效。更通用的解决方案是使用 RVM 路径变量:
# The following code loads RVM as user or system install:
[[ -s "$rvm_path/scripts/rvm" ]] && . "$rvm_path/scripts/rvm"
回答by Behzad
I just had to invoke source ~/.bash_profile
我只需要调用源 ~/.bash_profile
回答by gordonbanderson
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:
在全新安装 Ubuntu 12.04 时,我遇到了同样的问题。RVM 安装程序创建或附加到一个名为 ~/.bash_login 的文件中,以避免原始问题的必要代码位:
[[ -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.
然而,这似乎没有被调用。将它添加到 ~/.bashrc 为我解决了这个问题。
回答by hahakubile
Installing RVM, See here http://octopress.org/docs/setup/rvm/
安装 RVM,请参见此处http://octopress.org/docs/setup/rvm/

