新手问题 ubuntu 下 rvm 在 oh-my-zsh 下出现了的问题

xiajian · May 22, 2015 · Last by kgen replied at May 23, 2015 · 4417 hits

几天前,本身朝圣的心态,试用了 zsh,确实相当的强大,但是,也发现了一些问题,主要和 rvm 相关的。

首先是,rvm 补全时,比如rvm cur<TAB>时会出现这样:

rvm curWarning! PATH is not properly set up, '/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-1.9.3-p551@tophold'.
current 
Warning! PATH is not properly set up, '/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-1.9.3-p551@tophold'.
ruby-1.9.3-p551@tophold

这个,还可以忍受,难以忍受的是,设定的.ruby-gemset.ruby-version时而能工作,时而不能工作。比如,使用rvm use 1.9.3@tophold --default设定了默认的环境。

然后,尝试一下 ruby 2.1.2 和 rails 4,锁定 ruby 和 gemset,然后 bundle 成功了,重开了一个 tab 页,rvm 的环境又变回去了。请问,各位大神,有遇到这个问题吗??

我就对 zsh 不感冒,系统默认什么就用什么,懒得处理这类问题。

#1 楼 @rei 用 zsh 就图比用 bash 少敲点字的。再加上能提示 git 版本的不用,每次 git st(有一次在项目目录中搞错版本误操作了).

# .bashrc
WHITE="\[\033[0m\]"
YELLOW="\[\033[0;33m\]"
PS1="\w $YELLOW\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)$WHITE\$ "

#3 楼 @rei 哦,谢谢,我试试看。

我也有这个问题,各种谷歌,stackoverflow 无果,ruby 重装了好几遍,最后卸载了oh-my-zsh

rvm curWarning! PATH is not properly set up, '/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-1.9.3-p551@tophold'.
current 

#5 楼 @flowerwrong 原因是 rvm 要求把 .rvm/xx/bin 放到 PATH 的第一位。zsh 看 .zshrc 里面有 rvm 的配置了没,后面有没有其它修改 PATH 的配置。

#5 楼 @flowerwrong 我换了一个 shell 框架,bash_it,发现,这个问题更严重了,几乎,没执行一个命名,都会弹出这个提示:

ll
total 132
drwxrwxr-x 26 xiajian xiajian 4096  5月 22 17:49 .
drwxr-xr-x 81 xiajian xiajian 4096  5月 22 18:18 ..
drwxrwxr-x  2 xiajian xiajian 4096  5月 20 15:08 archives
....
drwxrwxr-x  2 xiajian xiajian 4096  5月 20 15:08 tmp
drwxrwxr-x  2 xiajian xiajian 4096  5月 22 16:54 user
-rw-rw-r--  1 xiajian xiajian    8  5月 20 14:48 VERSION
drwxrwxr-x  2 xiajian xiajian 4096  5月 22 17:14 wrappers
Warning! PATH is not properly set up, '/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-1.9.3-p551@tophold'.

追踪了一下,这个提示大概出现在 .rvm/scripts/functions/cli中的第 27 到 34 行:

__rvm_path_match_gem_home_check_warning_missing()
{
  rvm_warn "\
Warning! PATH is not properly set up, \$GEM_HOME is not set,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use $1'."
}

所以,我觉得,这不是 oh-my-zsh 的问题,应该是为了自动补全 rvm,执行的 rvm 上面的函数的问题。不明白的是,为何哪个 path 要放在第一个。

#6 楼 @rei 哪个.rvm/xx/bin目录是通过命令设置的,不至于要向文件中写内容吧。ps: 之前用 bash 时,一直都是正常的。

#6 楼 @rei 配置了,其他.bashrc .bash_profile .profile 里面的 rvm 配置都删除了。只保留了.zshrc 里面的。 我没理解你说的第一位是什么意思? export PATH=$PATH:rvm_path

10 Floor has deleted

#11 楼 @rei 我的 PATH 是这样的/home/xiajian/.nvm/v0.10.35/bin:/home/xiajian/.rbenv/bin:/home/xiajian/.pyenv/bin:./node_modules/.bin:/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin:/home/xiajian/.rvm/gems/ruby-1.9.3-p551@global/bin:/home/xiajian/.rvm/rubies/ruby-1.9.3-p551/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/xiajian/.rvm/bin:/home/xiajian/.rvm/bin:/opt/nginx/sbin:/home/xiajian/.gem/ruby/1.9.1/bin:/home/xiajian/.bash_it/plugins/available/todo:/home/xiajian/.rvm/bin:/home/xiajian/.rvm/bin 你的意思是,要/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin 这设置为第一个。

#12 楼 @xiajian 把 rvm 的配置移到配置文件的底部。现在至少看见有 .nvm .rbenv .pyenv 在 PATH 前面。

#13 楼 @rei 好的,我试试。

#13 楼 @rei 我大概明白了,在 oh-my-zsh 以及 bash-it 中,rvm 确实没办法将/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin放到第一个,而在纯的 bash 中,却可以做到, /home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin:/home/xiajian/.rvm/gems/ruby-1.9.3-p551@global/bin:/home/xiajian/.rvm/rubies/ruby-1.9.3-p551/bin:/home/xiajian/.rvm/bin:/home/xiajian/.nvm/v0.10.35/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games。尽管我觉得配置都一样。各种 shell 框架中的 souce 执行 shell 文件,确实很坑爹啊。

我也好奇 rvm 为什么一定要占用 PATH 的首位。找到这个 issues https://github.com/rvm/rvm/issues/2050

似乎 rvm 切换版本的原理是把 PATH 首位去掉,再加上新的 PATH,如果 rvm 不是 PATH 首位就会有问题。

评论中的文本超出边界是怎么回事?

我今天又在 zsh 中尝试了一下,似乎不光 rvm 喜欢占 PATH 的首位。nvm 也喜欢占首位,而且,我今天遇到的问题是 nvm 把首位给抢过去了,这样问题就又出现了。

使用rvm use 1.9.3@tophold --default,命令只能维持一时的作用,重开一个 tab 页,依然如故。我怀疑,是升级的 rvm 版本的问题。

#18 楼 @xiajian 每次新开 tab 都是打开一个新的 shell,配置会重载一遍。

既然你也用 rbenv 了,那就不用 rvm 咯。rbenv 要求使用者自己配置 PATH,不动态修改 PATH 没有这个问题。

我是使用 PPA 安装,不用 vm 了。http://chloerei.com/2014/07/13/the-best-way-to-install-the-latest-version-of-ruby-on-ubuntu/

#19 楼 @rei 对于大多数不需要多版本共存的场景,这个真是太干净了 👍 不过 PPA 仓库由第三方维护,用的人不多,没人经常看源码的情况下,会不会有安全隐患?(不是怀疑节操,但毕竟以前有过类似的在开源项目注入恶意代码不被发现的)

#21 楼 @rei 知道怎样才能回退到之前的版本 rvm 吗,我在另一台机器上的 1.25.27 上就没有这个问题。

#22 楼 @xiajian 不知道。

#21 楼 @rei 哦,brightbox 这种有品牌的服务商,PPA 仓库还是比较可靠的。

You need to Sign in before reply, if you don't have an account, please Sign up first.