Ruby 安装的 RVM 不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4911504/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:20:17  来源:igfitidea点击:

RVM installed by Ruby not working?

ruby-on-railsrubyrvm

提问by Yash Desai

I installed RVM using the single instruction mentioned at the RVM website (using git).

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

Then I installed Ruby version 1.9.2 and 1.8.7 using:

然后我使用以下命令安装了 Ruby 版本 1.9.2 和 1.8.7:

rvm install 1.9.2
rvm install 1.8.7

However, I cannot find the Ruby binary. When I try to execute the command, I get the following error:

但是,我找不到 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

Here is the output of rvm info:

这是输出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 ([email protected]) [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]#

回答by the Tin Man

RVM requires a minor addition to your ~/.bashrcor ~/.bash_profileto initialize it when you log-in. It is specified in the installation docs in the Post Installsection. Did you do that?

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



Per your rvm infooutput, it looks like you haven't completed your installation. All the entries in the output should have corresponding values. So, I suspect you haven't added:

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

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

to your ~/.bashrcor ~/.bash_profileand then started a new session.

到您的~/.bashrc~/.bash_profile然后开始一个新的会话。

If you are doing a "Multi-User" installation then you'll need to do a lot more. Have you modified /etc/profile, or, if you are using Bash as your shell, have you modified /etc/bash.bashrcto include:

如果您正在进行“多用户”安装,那么您需要做更多的事情。您是否修改过/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

and started a new shell?

并开始一个新的外壳?

Personally I don't like the multi-user install as much as the single-user install, and don't recommend it but your mileage might vary.

就个人而言,我不像单用户安装那样喜欢多用户安装,也不推荐它,但您的里程可能会有所不同。



As a FYI: In a discussion with the RVM maintainers on IRC last year, they told me they do not recommend the system-wide installation, and instead recommend the local "single-user" installation, even for servers.

仅供参考:去年在与 IRC 上的 RVM 维护人员的讨论中,他们告诉我他们不推荐系统范围的安装,而是推荐本地“单用户”安装,即使是服务器也是如此。

回答by Micael Queiroz

I installed Ruby on Rails on a Ubuntu 11.10 VM, using "HOW TO INSTALL RUBY ON RAILS IN UBUNTU 11.10".

我在 Ubuntu 11.10 VM 上安装了 Ruby on Rails,使用“如何在 UBUNTU 11.10 中安装 RAILS”。

After installing it, I was running into the same issue. The only thing that seems to be missing from the tutorial in my opinion, is the following command:

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

rvm --default use 1.9.2

Although Ruby is properly installed, RVM seems to redefine in each session Ruby is to be used. The problem was that the default Ruby pointed to the "system ruby", and, in my case, this one pointed to nowhere and made the call rvm inforeturn a result similar to the initial post.

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

To solve this issue, one of the follwings commands must be used:

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

rvm  --default use 1.9.x

or (valid only for the current session)

或(仅对当前会话有效)

rvm use 1.9.x

Before I could start the server, I also came across "ExecJS and could not find a JavaScript runtime". As proposed in several answers, I solved it by adding the following lines to the Gemfile.

在启动服务器之前,我还遇到了“ ExecJS 并且找不到 JavaScript 运行时”。正如几个答案中所提出的,我通过将以下几行添加到 Gemfile 中解决了这个问题。

gem 'execjs'

gem 'therubyracer'

and running bundle installafterwards.

然后运行bundle install

回答by Fredy

I had similar problem (using Ubuntu 13.10) to solve it

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

$ source .rvm/scripts/rvm 

and for long term

并且长期

$ 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]

回答by Bruno Paulino

I had ran in the same issue. I just executed the command:

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

/bin/bash --login

回答by Michelle Tilley

Are you making sure to source /usr/local/lib/rvm? echo 'source /usr/local/lib/rvm' >> ~/.bashrcand relog via SSH/start a new instance of Bash.

你确定来源 /usr/local/lib/rvm 吗?echo 'source /usr/local/lib/rvm' >> ~/.bashrc并通过 SSH 重新登录/启动一个新的 Bash 实例。



To clarify, since there is some confusion: there are two ways to install RVM: a "per user" install, and a "system wide" install.

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

For most day-to-day use, you want to use a "per user" install, which installs RVM into ~/.rvm. System-wide installs are good for servers, where one set of Rubies should be used. The default location for RVM in this case is /usr/local/rvm.

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

Based on your question, it appears you've installed RVM as a system-wide install.

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

To use RVM, it must be initialized by running a script each time you log in. To do this easily, you include the file in your ~/.bashrcfile (or ~/.bash_profileif you're on OS X), so that it is automatically run each time you log in. For a per user install, add the following text to the file:

要使用 RVM,必须在每次登录时通过运行脚本对其进行初始化。要轻松做到这一点,您可以将该文件包含在您的~/.bashrc文件中(或者~/.bash_profile如果您使用的是 OS X),这样每次您登录时它都会自动运行登录。对于每个用户安装,将以下文本添加到文件中:

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

for system wide installs, use this text instead:

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

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

If you do indeed have a system-wide install, you will also need to make sure you are a member of the rvm group; type the following to do so:

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

sudo adduser `whoami` rvm

Once you have made the necessary changes, log out of your session and then log back in. Once you have done so, rvm use 1.9.2should set a bunch of environment variables, which you can see by typing rvm info. If all is well, rubyshould execute correctly.

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

回答by zee

Here is how to fix undetected Rubies inside RVM.

以下是修复 RVM 中未检测到的 Ruby 的方法。

First, I did a sanity check to make sure that very thing looks great, then ran

首先,我做了一个健全性检查以确保这件事看起来很棒,然后运行

rvm use ruby --default

which did the job. It comes down to this command:

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

-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)

回答by Jared Knipp

Ruby is not in your path. In simple terms, RVM handles the switching of Ruby in your path. Look at the output of the command-line tool

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

printenv

You should see something similar to:

您应该会看到类似于以下内容的内容:

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

See Tin Man's response, it should get you were you need to go.

看到 Tin Man 的回应,它应该让你知道你需要去。

回答by Shad

I noticed that sourceline was correctly in .bash_profile but I kept getting ruby command not found. So, when I checked rvm list, I figured out none ruby was selected:

我注意到该source行在 .bash_profile 中是正确的,但我一直找不到 ruby​​ 命令。所以,当我检查时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

then I did the selection through rvm use 2.4.0and checked again

然后我做了选择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

Look the arrow close the installed ruby and the commented subtitles. After that ruby -vfinally answered me

查看箭头关闭已安装的 ruby​​ 和注释字幕。在那之后ruby -v终于回答了我

ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

I hope this help. Cheers.

我希望这会有所帮助。干杯。

edit:You can use rvm --default use 2.4.0to set it as default ruby version

编辑:您可以使用rvm --default use 2.4.0将其设置为默认 ruby​​ 版本

回答by u4762009

rvm use 2.6.3 --defaultcan fix it, but when I shut down my Ubuntu, the problem appearance once again!! this link helped me.https://github.com/rvm/rvm/issues/3682

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

  1. sudo vim .bash_profile
  2. add the following two lines:
  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    

回答by James L.

I set my shell as a login shell (open terminal > Edit > Profile Preferences > Command tab > "Run command as a login shell") though I'm not 100% sure it's needed.

我将我的 shell 设置为登录 shell(打开终端 > 编辑 > 配置文件首选项 > 命令选项卡 >“作为登录 shell 运行命令”),尽管我不是 100% 确定需要它。

Once you're done installing RVM + Ruby though, you must specify which ruby you will be using. I like to use

完成 RVM + Ruby 的安装后,您必须指定将使用的 ruby​​。我喜欢用

rvm use --latest --default

rvm use --latest --default