简体   繁体   English

如何检查Ruby中的Gem管理RVM是否已正确安装?

[英]How do I check if RVM for Gem management in Ruby was properly installed?

Is there a command to see if RVM was probably installed? 是否有命令查看是否可能安装了RVM? I just went through the setup process of RVM and would like to test it out. 我刚刚完成了RVM的设置过程,并希望对其进行测试。

Also, since I have (or will eventually have) RVM, should I no longer use apt-get to download libraries/gems and always do that through RVM? 另外,既然我已经(或者最终会拥有)RVM,我是否应该再使用apt-get来下载库/ gems并且总是通过RVM做到这一点?

rvm -v is a good start and then per the installation instructions ( link ) typing in $ type rvm | head -1 rvm -v是一个很好的开始,然后根据安装说明( 链接 )键入$ type rvm | head -1 $ type rvm | head -1 should return 'rvm is a function'. $ type rvm | head -1应该返回'rvm is a function'。 as to the second part yes you should just stick to installing gems with rvm using gem install (gemname here) and that will save you a good deal of trouble 至于第二部分是的,你应该坚持用rvm使用gem install(这里是gemname)安装宝石,这样可以省去很多麻烦

First, make sure your RVM is properly installed: 首先,确保正确安装了RVM:

https://rvm.beginrescueend.com/rvm/install/ https://rvm.beginrescueend.com/rvm/install/

rvm info is a good way of finding out if everything went well. rvm info是一个很好的方法来查明一切进展顺利。

Regarding gems, I'd say manage them through the RVM-installed Rubies, they have some advantages like gemsets: 关于宝石,我会说通过RVM安装的Rubies来管理它们,它们有一些优点,比如gemsets:

https://rvm.beginrescueend.com/gemsets/ https://rvm.beginrescueend.com/gemsets/

Now I now there's always been some controversy between people who prefer native packages over gems (and there are some valid reasons for that, but this is a discussion for another time), but I think RVM tipped the scale a bit here, as do the problems with Ruby packages on Debian: 现在我现在总是在那些喜欢原生包装而不是宝石的人之间存在一些争议(并且有一些正当理由,但这是另一次的讨论),但我认为RVM在这里略微提升了规模,就像Debian上Ruby包的问题:

http://www.lucas-nussbaum.net/blog/?p=617 http://www.lucas-nussbaum.net/blog/?p=617

There are several cases: 有几种情况:

  • RVM is not installed 未安装RVM
  • RVM is installed but not used (ie its bindir is added to PATH but it is not sourced) RVM已安装但未使用(即其bindir已添加到PATH但未获取)
  • RVM is installed and used but not loaded (ie it is sourced but you are checking that from a script) RVM已安装并使用但未加载(即它是来源但您从脚本中检查)
  • RVM is installed and used 安装并使用RVM

The only way I've found to test for all 4 cases is checking for environment variables starting with rvm_ : 我发现测试所有4种情况的唯一方法是检查以rvm_开头的环境变量:

env | egrep -v '^PATH' | egrep '^rvm_path'

We could check for variables like MY_RUBY_HOME or GEM_HOME but these can be overriden manually by user so it does not guarantee we are using RVM. 我们可以检查MY_RUBY_HOMEGEM_HOME等变量,但这些变量可以由用户手动覆盖,因此不保证我们使用的是RVM。

If you are going to use the above command in script you can reword it like the following and check for exit code: 如果您要在脚本中使用上述命令,可以像下面这样重写它并检查退出代码:

env | egrep -v '^PATH' | egrep -q '^rvm_path'

Of course if you just need to find out if RVM is there on disk and is accessible you can go with simpler ones like other suggested here. 当然,如果您只是需要了解RVM是否在磁盘上并且可以访问,您可以使用其他建议的更简单的RVM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM