RVM/rbenv [已解决] 安装好 rvm 之后,开启新终端 rvm 命令就运行不了了,求教~~~~

jochen · 2013年12月12日 · 最后由 jochen 回复于 2014年06月01日 · 11065 次阅读

本人 MAC,依照http://ruby-china.org/wiki/install_ruby_guideruby,这里安装好环境以后,在没有关闭终端的情况下一切都可以正常使用,当另外开一个终端,或者关闭再新开一个终端, -v 可以运行,但 rvm -v 和 rails -v 都不能正常运行了,返回的结果是: 另外,我查看了.bashrc 文件,有这样一行: PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

请教大家,这个问题出在哪里?谢谢。

=============== 解决方案:(感谢:@floger@ashchan) 我发现我的配制文件中有一个叫.bash_profile 的文件,我把配制文件复制到这个文件中,问题解决了。。。 ====真相=====

  1. Reload shell configuration & test

Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command:

ser$ source ~/.rvm/scripts/rvm

If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output 'rvm is a function' as shown below.

user$ type rvm | head -n 1

rvm is a function NOTE: Before reporting problems check 'rvm notes' as it might contain important information. http://rvm.io/rvm/install

.bashrc 里还应该加上这样一句:

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

#2 楼 @ashchan 谢谢,已经加上了这句,但是在新终端,还是找不到命令。 MacBook-Pro:~ Jochen$ rvm -v -bash: rvm: command not found

#1 楼 @floger 你好,谢谢,根据你的描述,如果我在新终端中选执行“source ~/.rvm/scripts/rvm” 再测试 rvm -v ,是可以正常运行的。结果是: MacBook-Pro:~ Jochen$ source ~/.rvm/scripts/rvm MacBook-Pro:~ Jochen$ rvm -v rvm 1.24.8 (stable) by Wayne E. Seguin [email protected], Michal Papis [email protected] [https://rvm.io/]

但,不能每次都这样走先 source 吧?请教。。。

@jochen 一般一次就可以了,

#5 楼 @floger ,这里,我还有一个情况要汇报一下: 在新的终端中,我执行:gem list: *** LOCAL GEMS ***

CFPropertyList (2.2.0) libxml-ruby (2.6.0) nokogiri (1.5.6) sqlite3 (1.3.7)

当我,执行完:source ~/.rvm/scripts/rvm 再执行:gem list: *** LOCAL GEMS ***

bigdecimal (1.2.0) bundler (1.3.5) bundler-unload (1.0.2) executable-hooks (1.2.6) io-console (0.4.2) json (1.7.7) minitest (4.3.2) psych (2.0.0) rake (0.9.6) rdoc (4.0.0) rubygems-bundler (1.4.2) rvm (1.11.3.8) test-unit (2.0.0.0)

这是什么情况???

@jochen 你关闭当前的终端,先执行 rvm 一下,看看 rvm 有没有已经加载。如果还是没有,贴一下你的

.bashrc 

文件看看你的配置。

#7 楼 @floger 谢谢,我确定,关闭终端以后,再新终端中没有加载 rvm。因为我运行 rvm 会返回找不到命令 以下是我的.bashrc 文件的内容:

@jochen 按这个步骤试试,重新打开终端看看 重新加载 bashrc:

$ source ~/.bashrc

加载 rvm 的配置文件:

$ source ~/.rvm/scripts/rvm

测试是否安装配置成功:

$ type rvm | head -n 1
rvm is a function

如果输出 rvm is a function 代表安装成功,如果输出 rvm is a hash,重新加载 rvm 的配置文件。

#2 楼 @ashchan #9 楼 @floger 感谢您的帮助,我突然间发现我的配制文件中有一个叫.bash_profile 的文件,我将配制项加载到这个文件中,居然就好了,谢谢各位帮我找到原因,谢谢。。!!!!!!

#10 楼 @jochen 那应该是 .bashrc 没有加载。你也可以在 .bash_profile 中加入这一行:

if [ -f ~/.bashrc ]; then
  source ~/.bashrc
fi

rvm 需要写配置文件,但是不同的 shell 读取的配置文件不同,所以有可能写错了文件。

土方法:

在 .bashrc .bash_profile .profile 里面各写一条 echo,没有这个文件就跳过,然后开一个新终端看看输出什么,就是读取了什么配置文件。

#11 楼 @ashchan #12 楼 @Rei

if [ -f ~/.bashrc ]; then
  source ~/.bashrc
fi

if [ -f ~/.profile ]; then
  source ~/.profile
fi
需要 登录 后方可回复, 如果你还没有账号请 注册新账号