簡體   English   中英

Ruby 安裝的 RVM 不工作?

[英]RVM installed by Ruby not working?

我使用 RVM 網站上提到的單一指令(使用 git)安裝了 RVM。

然后我使用以下命令安裝了 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]#

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

並開始一個新的外殼?

就個人而言,我不像單用戶安裝那樣喜歡多用戶安裝,也不推薦它,但你的里程可能會有所不同。


僅供參考:去年在 IRC 上與 RVM 維護者的討論中,他們告訴我他們不推薦系統范圍的安裝,而是推薦本地“單用戶”安裝,即使對於服務器也是如此。

我有類似的問題(使用 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]

我使用“ 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 指向“系統紅寶石”,而在我的例子中,這個指向任何地方並使調用rvm info返回類似於初始帖子的結果。

要解決此問題,必須使用以下命令之一:

rvm  --default use 1.9.x

或(僅對當前會話有效)

rvm use 1.9.x

在啟動服務器之前,我還遇到了“ ExecJS 並且找不到 JavaScript 運行時”。 正如幾個答案中所建議的,我通過將以下行添加到 Gemfile 來解決它。

gem 'execjs'

gem 'therubyracer'

然后運行bundle install

我遇到了同樣的問題。 您可能需要先登錄:

/bin/bash --login

以下是修復 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)

你確定來源 /usr/local/lib/rvm 嗎? echo 'source /usr/local/lib/rvm' >> ~/.bashrc並通過 SSH 重新登錄/啟動一個新的 Bash 實例。


澄清一下,因為存在一些混淆:有兩種安裝 RVM 的方法:“每個用戶”安裝和“系統范圍”安裝。

對於大多數日常使用,您希望使用“每用戶”安裝,將 RVM 安裝到~/.rvm中。 系統范圍的安裝對於服務器來說是好的,應該使用一組 Rubies。 在這種情況下,RVM 的默認位置是/usr/local/rvm

根據您的問題,您似乎已將 RVM 安裝為系統范圍的安裝。

要使用 RVM,必須在您每次登錄時通過運行腳本來初始化它。為了輕松地做到這一點,您將該文件包含在您的~/.bashrc文件中(如果您使用的是 OS X,則為~/.bash_profile ),所以它會在您每次登錄時自動運行。對於每用戶安裝,將以下文本添加到文件中:

[[ -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應該設置一堆環境變量,您可以通過鍵入rvm info查看這些變量。 如果一切順利, ruby應該可以正確執行。

Ruby 不在你的道路上。 簡單來說,RVM 處理路徑中 Ruby 的切換。 查看命令行工具的輸出

printenv

您應該會看到類似於以下內容的內容:

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

看看 Tin Man 的回應,它應該讓你知道你需要去哪里。

我注意到source行在.bash_profile 中是正確的,但我一直找不到 ruby 命令。 所以,當我檢查rvm list時,我發現沒有選擇 ruby:

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]

我希望這有幫助。 干杯。

編輯:您可以使用rvm --default use 2.4.0將其設置為默認的 ruby 版本

我將我的 shell 設置為登錄 shell(打開終端 > 編輯 > 配置文件首選項 > 命令選項卡 >“將命令作為登錄 shell 運行”),但我不能 100% 確定是否需要它。

一旦你完成了 RVM + Ruby 的安裝,你必須指定你將使用哪個 ruby。 我喜歡用

rvm use --latest --default

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    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM