ruby-on-rails - bundle 安装错误,意外 ':'

标签 ruby-on-rails ruby

我知道网上有很多问题或类似问题,但它不适合我的情况。 我正在安装 redmine,当我调用 bundle install 时,出现此错误:

[!] There was an error parsing `Gemfile`: compile error - syntax error, unexpected ':', expecting $end
gem 'tzinfo-data', platforms: [:mingw, :x64_mingw, :mswin, :jruby]
                            ^. Bundler cannot continue.

错误在这一行(以->为前缀的那一行):

   source 'https://rubygems.org'

   if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.5.0')
     abort "Redmine requires Bundler 1.5.0 or higher (you're using #{Bundler::VERSION}).\nPlease update with 'gem update bundler'."
   end

   gem "rails", "4.2.3"
   gem "jquery-rails", "~> 3.1.3"
   gem "coderay", "~> 1.1.0"
   gem "builder", ">= 3.0.4"
   gem "request_store", "1.0.5"
   gem "mime-types"
   gem "protected_attributes"
   gem "actionpack-action_caching"
   gem "actionpack-xml_parser"
   gem "loofah", "~> 2.0"

   # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
-> gem 'tzinfo-data', platforms: [:mingw, :x64_mingw, :mswin, :jruby]
   gem "rbpdf", "~> 1.18.6"

   # Optional gem for LDAP authentication
   group :ldap do
     gem "net-ldap", "~> 0.3.1"
   end

就像在许多其他线程中所说的那样,原因可能是这段代码使用了“新的”ruby 1.9 哈希语法。但是,查看版本:

$ ruby -v
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
$ gem -v
2.2.2
$ bundle -v
Bundler version 1.10.6
$ bundle exec ruby -v
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
$ which bundler
/usr/local/bin/bundler

编辑:按照 Arsen 的建议,此命令显示问题出在哪里,我将阅读一些有关 ruby​​ 和虚拟环境的文档以使其以正确的方式工作:

$ bundle env
Environment

    Bundler   1.10.6
    Rubygems  1.8.24
    Ruby      1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
    Git       2.5.1

Bundler settings

    without
      Set for your local app (/home/leo/http/redmine.leo-flaventin.com/redmine/.bundle/config): "development:test"

Gemfile
   [...] #The redmine Gemfile

然后,我认为gem正在使用ruby 2.2(但我不确定)所以我认为应该没有任何问题,但由于我并不真正了解ruby universe并且实际上存在错误,我肯定错了。这就是为什么我请求社区的帮助......

那么对正在发生的事情有什么想法吗?

(我可以使用旧的哈希语法更正文件,但由于我想使用最新版本,我认为这只会解决问题)

最佳答案

这是一个老问题,但由于它尚未解决并且我遇到了同样的问题,所以我将分享我的解决方案。

我通过 apt-get 在我的 debian 7 服务器上安装了 ruby​​。尝试运行 bundle install 时,我收到与上述相同的错误消息:

[!] 解析 Gemfile 时出错:编译错误 - 语法 错误,意外的 ':',期待 $end

我的想法是通过 ruby​​ 版本管理器安装 ruby​​。

  1. 删除 ruby sudo apt-get remove ruby​​ && sudo apt-get autoremove
  2. 通过 ruby​​ 版本管理器 (rvm) 安装 ruby​​ \curl -sSL https://get.rvm.io | sudo bash -s stable --rails
  3. 如果 2. 失败,添加签名(根据提示)\curl -sSL https://get.rvm.io | sudo bash -s stable --rails
  4. 将用户添加到组 sudo usermod -aG rvm USERNAME && sudo usermod -aG rvm www-data
  5. 注销和登录
  6. 重新运行您的bundle install命令
  7. 如果您仍然有问题,它们应该与应用程序相关。对我来说,我还必须安装 sudo apt-get install libmysqlclient-dev

我在学习有关此 blog 的教程时看到了此解决方案

关于ruby-on-rails - bundle 安装错误,意外 ':',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32549499/

相关文章:

ruby-on-rails - 用户有很多 :users, 还是我必须为基于 friend 的社交网络使用另一种方式?

ruby - 为什么 gems 安装在与我运行的 Ruby 版本不同的目录中?

ruby-on-rails - 设计中未初始化的常量 ActiveSupport::SecureRandom

ruby-on-rails - 无法加载此类文件——coffee_script

ruby-on-rails - 捆绑安装请求手动执行每个 gem 安装 - 如何避免?

ruby-on-rails - 我尝试在安装 cocoapods 后在 Rail 上安装 ruby​​,但它有同样的错误

Ruby:如何在字符串插值内的符号上使用 gsub 方法#{}

ruby-on-rails - 是否可以在没有基于套接字的框架的情况下构建基于 Web 的聊天客户端?

ruby-on-rails - 由于字段不存在而创建不保存记录

ruby-on-rails - After_save 带参数