Ruby安装的RVM无法正常工作?

时间:2011-02-06 04:05:08

标签: ruby-on-rails ruby rvm

我使用RVM网站上提到的单个指令安装了RVM(使用git)。

然后我使用:

安装了Ruby版本1.9.2和1.8.7
rvm install 1.9.2
rvm install 1.8.7

但是,我找不到Ruby二进制文件。当我尝试执行命令时,出现以下错误:

[root@server1 support]# rvm use 1.9.2
Using /usr/local/rvm/gems/ruby-1.9.2-p136

[root@server1 support]# ruby
-bash: ruby: command not found

以下是rvm info的输出:

[root@server1 support]# rvm info

system:

  system:
    uname:       "Linux server1.myserver.com 2.6.18-194.26.1.el5.028stab070.14 #1 SMP Thu Nov 18 16:34:01 MSK 2010 x86_64 x86_64 x86_64 GNU/Linux"
    bash:        "/bin/bash => GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)"
    zsh:         " => not installed"

  rvm:
    version:      "rvm 1.2.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"

  homes:
    gem:          "not set"
    ruby:         "not set"

  binaries:
    ruby:         ""
    irb:          ""
    gem:          ""
    rake:         ""

  environment:
    PATH:         "/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/rvm/bin"
    GEM_HOME:     ""
    GEM_PATH:     ""
    MY_RUBY_HOME: ""
    IRBRC:        ""
    RUBYOPT:      ""
    gemset:       ""


[root@server1 support]#

10 个答案:

答案 0 :(得分:60)

RVM在您登录时需要对~/.bashrc~/.bash_profile进行少量添加以对其进行初始化。它在Post Install部分的安装文档中指定。你做到了吗?


根据您的rvm info输出,您似乎还没有完成安装。输出中的所有条目都应具有相应的值。所以,我怀疑你没有添加:

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

~/.bashrc~/.bash_profile,然后开始新会话。

如果您正在进行“多用户”安装,那么您需要做更多事情。您是否修改了/etc/profile,或者,如果您使用Bash作为shell,则修改了/etc/bash.bashrc以包含:

# Load RVM if it is installed,
#  first try to load  user install
#  then try to load root install, if user install is not there.
if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
  . "$HOME/.rvm/scripts/rvm"
elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
  . "/usr/local/rvm/scripts/rvm"
fi

并开始了一个新的shell?

我个人不喜欢单用户安装的多用户安装,不推荐它,但你的里程可能会有所不同。


作为一个参考:在去年与IRC的RVM维护者的讨论中,他们告诉我他们不推荐系统范围的安装,而是推荐本地“单用户”安装,即使是服务器。

答案 1 :(得分:13)

我使用“HOW TO INSTALL RUBY ON RAILS IN UBUNTU 11.10”在Ubuntu 11.10 VM上安装了Ruby on Rails。

安装后,我遇到了同样的问题。在我看来,教程中似乎唯一缺少的是以下命令:

rvm --default use 1.9.2

虽然Ruby已正确安装,但RVM似乎在每个会话中重新定义了Ruby。问题是默认的Ruby指向“系统ruby”,在我的情况下,这个指向无处,并使调用rvm info返回类似于初始帖子的结果。

要解决此问题,必须使用以下一个follwings命令:

rvm  --default use 1.9.x

或(仅对当前会话有效)

rvm use 1.9.x

在我启动服务器之前,我还遇到了“ExecJS and could not find a JavaScript runtime”。正如几个答案中提出的,我  通过在Gemfile中添加以下行来解决它。

gem 'execjs'

gem 'therubyracer'

然后运行bundle install

答案 2 :(得分:11)

我有类似的问题(使用Ubuntu 13.10) 解决它

$ source .rvm/scripts/rvm 

并且长期

$ echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc

$ ruby -v


The program 'ruby' can be found in the following packages:
 * ruby1.8
 * ruby1.9.1
Try: sudo apt-get install <selected package>

$ source .rvm/scripts/rvm

$ ruby -v

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]

答案 3 :(得分:4)

您确定要使用/ usr / local / lib / rvm吗? echo 'source /usr/local/lib/rvm' >> ~/.bashrc并通过SSH重新启动/启动Bash的新实例。


澄清一下,由于存在一些混淆:有两种方法可以安装RVM:“每用户”安装和“系统范围”安装。

对于大多数日常使用,您希望使用“每用户”安装,将RVM安装到~/.rvm。系统范围的安装适用于服务器,其中应使用一组Rubies。在这种情况下,RVM的默认位置是/usr/local/rvm

根据您的问题,您似乎已将RVM安装为系统范围的安装。

要使用RVM,必须在每次登录时通过运行脚本对其进行初始化。要轻松完成此操作,请将文件包含在~/.bashrc文件中(如果您正在使用~/.bash_profile OS X),以便每次登录时自动运行。对于每用户安装,将以下文本添加到文件中:

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

对于系统范围的安装,请改用此文本:

[[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"

如果确实有系统范围的安装,您还需要确保您是rvm组的成员;键入以下内容:

sudo adduser `whoami` rvm

完成必要的更改后,请退出会话,然后重新登录。完成后,rvm use 1.9.2应设置一组环境变量,您可以通过键入{{1 }}。如果一切顺利,rvm info应该正确执行。

答案 4 :(得分:4)

以下是如何在RVM中修复未检测到的Rubies。

首先,我做了一个完整性检查,以确保事情看起来很棒,然后运行

rvm use ruby --default

完成了这项工作。它归结为这个命令:

-SVE1411EGXB:~/code$ cd app1/
  -SVE1411EGXB:~/code/app1$ rails s
The program 'rails' can be found in the following packages:
 * ruby-railties-3.2
 * ruby-railties-4.0
Try: sudo apt-get install <selected package>
  -SVE1411EGXB:~/code/app1$ rails s
The program 'rails' can be found in the following packages:
 * ruby-railties-3.2
 * ruby-railties-4.0
Try: sudo apt-get install <selected package>
  -SVE1411EGXB:~/code/app1$ which ruby
  -SVE1411EGXB:~/code/app1$ which gem
  -SVE1411EGXB:~/code/app1$ rvm list

rvm rubies

=* ruby-2.1.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

  -SVE1411EGXB:~/code/app1$ \curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz

Upgrading the RVM installation in /home  /.rvm/
    RVM PATH line found in /home  /.profile /home  /.bashrc /home  /.zshrc.
    RVM sourcing line found in /home  /.bashrc /home  /.bash_profile /home  /.zlogin.
Upgrade of RVM in /home  /.rvm/ is complete.

# nullsoulexception,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io

Upgrade Notes:

  * No new notes to display.

  -SVE1411EGXB:~/code/app1$ rails s
The program 'rails' can be found in the following packages:
 * ruby-railties-3.2
 * ruby-railties-4.0
Try: sudo apt-get install <selected package>
  -SVE1411EGXB:~/code/app1$ source ~/.rvm/scripts/rvm
  -SVE1411EGXB:~/code/app1$ rvm requirements
Checking requirements for ubuntu.
Requirements installation successful.
  -SVE1411EGXB:~/code/app1$ rvm get stable
Downloading https://get.rvm.io
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz

Upgrading the RVM installation in /home  /.rvm/
    RVM PATH line found in /home  /.profile /home  /.bashrc /home  /.zshrc.
    RVM sourcing line found in /home  /.bashrc /home  /.bash_profile /home  /.zlogin.
Upgrade of RVM in /home  /.rvm/ is complete.

# nullsoulexception,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io

Upgrade Notes:

  * No new notes to display.

RVM reloaded!
  -SVE1411EGXB:~/code/app1$ rvm reload
RVM reloaded!
  -SVE1411EGXB:~/code/app1$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-head] # security released on head
[ruby-]1.9.3[-p547]
[ruby-]2.0.0-p451
[ruby-]2.0.0[-p481]
[ruby-]2.1.1
[ruby-]2.1[.2]
[ruby-]2.1-head
ruby-head

# GoRuby
goruby

# Topaz
topaz

# TheCodeShop - MRI experimental patches
tcs

# jamesgolick - All around gangster
jamesgolick

# Minimalistic ruby implementation - ISO 30170:2012
mruby[-head]

# JRuby
jruby-1.6.8
jruby[-1.7.12]
jruby-head

# Rubinius
rbx-2.0.0
rbx-2.1.1
rbx[-2.2.7]
rbx-head

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Kiji
kiji

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# Opal
opal

# IronRuby
ironruby[-1.1.3]
ironruby-head

  -SVE1411EGXB:~/code/app1$ ruby -v
The program 'ruby' can be found in the following packages:
 * ruby
 * ruby1.8
Try: sudo apt-get install <selected package>
  -SVE1411EGXB:~/code/app1$ rvm use ruby --default
Using /home  /.rvm/gems/ruby-2.1.2
  -SVE1411EGXB:~/code/app1$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  -SVE1411EGXB:~/code/app1$ rails s
=> Booting WEBrick
=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)

答案 5 :(得分:4)

我曾经遇到过同样的问题。我刚刚执行了命令:

/bin/bash --login

答案 6 :(得分:2)

Ruby不在你的道路上。简单来说,RVM处理路径中Ruby的切换。查看命令行工具的输出

printenv

你应该看到类似的东西:

PATH=/Users/myuser/.rvm/gems/jruby-1.5.6/bin

请参阅Tin Man的回复,它应该让你得到你需要去的。

答案 7 :(得分:1)

rvm use 2.6.3 --default可以修复它,但是当我关闭Ubuntu时,问题再次出现! 此链接对我有所帮助。https://github.com/rvm/rvm/issues/3682

  1. sudo vim .bash_profile
  2. 添加以下两行:
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session as a function    

答案 8 :(得分:0)

我注意到{。1}}行在.bash_profile中是正确的,但我一直找不到ruby命令。所以,当我检查source时,我发现没有选择红宝石:

rvm list

然后我通过 rvm list rvm rubies ruby-2.4.0 [ x86_64 ] # Default ruby not set. Try 'rvm alias create default <ruby>'. # => - current # =* - current && default # * - default 进行了选择并再次检查

rvm use 2.4.0

查看箭头,关闭已安装的红宝石和评论的字幕。之后rvm list rvm rubies => ruby-2.4.0 [ x86_64 ] # Default ruby not set. Try 'rvm alias create default <ruby>'. # => - current # =* - current && default # * - default 终于回答了我

ruby -v

我希望这有帮助。欢呼声。

修改:您可以使用 ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux] 将其设置为默认的ruby版本

答案 9 :(得分:0)

我将我的shell设置为登录shell(打开终端&gt;编辑&gt;配置文件首选项&gt;命令选项卡&gt;&#34;运行命令作为登录shell&#34;)虽然我不是100%确定它需要。

一旦你完成了RVM + Ruby的安装,你必须指定你将使用哪个ruby。我喜欢用

rvm use --latest --default