【问题标题】:After installing RVM either Rails Server or Git not working安装 RVM 后,Rails Server 或 Git 无法正常工作
【发布时间】:2012-01-23 11:20:08
【问题描述】:

我又把它弄坏了,不幸的是我不知道为什么......

问题第一

使用在 RVM 安装期间创建的 .bash_profile 找不到 Git。在.profile 中添加从 mac 端口导出的旧路径通过将 ruby​​ 恢复到 1.8.7 来破坏 rails 服务器

我想我认出了

/opt/local/bin:
/opt/local/sbin:

成为.bash_profile 中的两个目录,这将使 Git 工作但会破坏新的 RVM ruby​​ 版本。

解决方案

所以这里的解决方案: 我正在使用 Mac Ports Git 版本。这就是它不会运行的原因,除非 Mac Ports 目录是路径的一部分。当 Mac Ports 目录来源于 RVM 时,Mac Ports Ruby 版本似乎优先于 RVM 版本。

这将破坏

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

这将工作:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

感谢@three 为我指明了正确的方向 :)

我是如何打破它的

同时使用 Ruby 和 Rails 版本以与我正在学习这两个版本的教程保持同步,RVM 这个名称不断出现,作为更方便地管理这些版本的工具。

我安装了它并让它工作

ruby -v
$ ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

rails -v
$ Rails 3.1.3

在此过程中,我的 .profile 开始失败,但我认为这是因为在 RVM 安装期间创建的 .bash_profile 的优先级。我期待着麻烦,但到目前为止一切都很好,一切正常,包括 Rails 服务器。

rails s
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-19 10:16:15] INFO  WEBrick 1.3.1
[2011-12-19 10:16:15] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-12-19 10:16:15] INFO  WEBrick::HTTPServer#start: pid=53018 port=3000

然后我想提交到 Git,但突然之间不再工作了

git
-bash: git: command not found

所以我比较了.profile.bash_profile,发现在最初安装 ruby​​、rails 和 git 时,Mac Ports 在.profile 中添加了一行代码(确定 100% 我对所有这三个都使用了 MacPorts)

##
# Your previous /Users/username/.profile file was backed up as /Users/username/.profile.macports-saved_2011-10-19_at_08:48:41
##

# MacPorts Installer addition on 2011-10-19_at_08:48:41: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

如果我使用此设置查询 ruby​​ 版本,我会得到:

ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10]

所以我的新手猜测是我在安装 RVM 的过程中破坏了路径变量。如果我将该行添加到 .bash_profile git 再次工作,但 rails 服务器没有。注意 ruby​​ 版本不匹配。:

rails s
/Users/username/.rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10]

Abort trap

使用 Mac Ports PATH 导出时我的 $PATH 的内容是:

echo $PATH
/opt/local/bin:
/opt/local/sbin:
/Users/username/.rvm/gems/ruby-1.9.2-p290/bin:
/Users/username/.rvm/gems/ruby-1.9.2-p290@global/bin:
/Users/username/.rvm/rubies/ruby-1.9.2-p290/bin:
/Users/username/.rvm/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/bin:
/usr/X11/bin:

另一方面,使用.bash_profile,这是 $PATH 内容:

echo $PATH
/Users/username/.rvm/gems/ruby-1.9.2-p290/bin:
/Users/username/.rvm/gems/ruby-1.9.2-p290@global/bin:
/Users/username/.rvm/rubies/ruby-1.9.2-p290/bin:
/Users/username/.rvm/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/bin:
/usr/X11/bin:

看起来很相似,除了这两个目录:

/opt/local/bin:
/opt/local/sbin:

所以我的猜测是,这就是它崩溃的地方......但我不知道该怎么做。

对于所有这些开发,Apple Computers、Unix、Ruby、Rails Stuff,我还是很陌生:(

非常感谢任何帮助。

谢谢 蒂姆

【问题讨论】:

  • 你的问题解决了吗?从您的编辑中无法确定

标签: ruby-on-rails ruby macos bash rvm


【解决方案1】:

将 RVM 行放在 macports 的导出路径之后,以便 ruby​​ 的 rvm 二进制文件优先

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

还可以考虑使用 homebrew 代替 macports,后者是维护 *nix 工具的更流畅的版本。

【讨论】:

  • 我试过了,但不幸的是它并没有解决问题。当 mac 端口导出位于 .profile 时,仍在获取错误的 ruby​​ 版本(1.8.7 而不是 1.9.2)
  • 你重新加载了rvm? rvm reload
  • 我认为问题在于这个版本的 git 存在于/opt/local/bin/git
  • .bash_profile 是否有另一个设置了不同值的 PATH 变量?如果是这样,请确保将 :$PATH 添加到其末尾。然后关闭并重新打开您的 Terminal.app 会话以重新加载新值。
  • 在 7 小时内无法发布此格式正确的内容。到时会做。谢谢你帮助我:)
【解决方案2】:

将此行插入 .bash_profile:

source "$HOME/.profile"

在 RVM 添加内容之前。

【讨论】:

    猜你喜欢
    • 2012-08-19
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    相关资源
    最近更新 更多