0

我正在学习 Rails,对 Macports 还很陌生。

rails server为我的项目运行时收到以下错误:

/...config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end

我相信这个语法错误是由于运行低于 1.9.0 的 Rails 版本造成的,因为ruby -v给了我ruby 1.8.7.

问题是我确定我已经安装了 ruby​​ 1.9.3

我已经运行port clean ruby19和各种组合来安装 ruby​​ 1.9.3

port install ruby19

port install ruby19 -nosuffix

两者都给我以下错误:

Error: org.macports.activate for port ruby19 returned: Image error: /opt/local/bin/erb is being used by the active ruby port. Please deactivate this port first, or use 'port -f activate ruby19' to force the activation.

如果我运行,port -f activate ruby19我会收到此错误:

--->  The following versions of ruby19 are currently installed:
--->      ruby19 @1.9.3-p194_3+doc (active)
--->      ruby19 @1.9.3-p194_3+doc+mactk
--->      ruby19 @1.9.3-p194_3+doc+nosuffix
Error: port activate failed: Registry error: Please specify the full version as recorded in the port registry.

我从这里去哪里?!

我基本上想要最快最简单的解决方案来启动和运行这个项目——我不需要在我的机器上安装多个版本的 ruby​​。

来吧,我知道我不能成为第一个遇到这个问题的人!RVM 真的是人们这样做的唯一方法吗?

提前谢谢了!

4

2 回答 2

2

使用rvm会少很多麻烦,可以在本地工作并且更新更频繁。您还可以使用 rbenv 或任何其他 ruby​​ 安装程序。节省一些时间并使用这些安装程序。

于 2012-09-16T19:27:21.307 回答
0

事实证明我已经安装了 ruby​​ (1.8.7) 的 macports。

我卸载了我所有的 macports ruby​​19 版本sudo port uninstall ...

停用活动版本sudo port -f deactivate ruby

并安装了不带后缀的 1.9.3 版本

sudo port install ruby19 +nosuffix

我收到了这个错误:

Image error: /opt/local/bin/gem is being used by the active rb-rubygems port. Please deactivate this port first, or use 'port -f activate ruby19' to force the activation.

所以跑了sudo port -f activate ruby19

现在当我跑步时,rails server我得到:

/opt/local/lib/ruby1.9/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)
from /opt/local/lib/ruby1.9/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /opt/local/lib/ruby1.9/1.9.1/rubygems.rb:1231:in `gem'
from /opt/local/bin/rails:22:in `<main>'

然后我更新了我的 gem 包和 rails:

sudo gem update --system
sudo gem uninstall rubygems-update
sudo gem install rails
sudo bundle install

结果:

Your bundle is complete! Use 'bundle show [gemname]' to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
  = 1.8.7 : gem install rdoc-data; rdoc-data --install
  = 1.9.1 : gem install rdoc-data; rdoc-data --install
 >= 1.9.2 : nothing to do! Yay!

关于 macports 和 ruby​​ 路径的有用讨论:MacPorts 如何安装软件包?如何激活通过 MacPorts 完成的 Ruby 安装?

很多人推荐 RVM https://rvm.io/,但对我来说,我现在只需要运行 1.9.2。

于 2012-09-21T07:28:15.690 回答