【问题标题】:Rails commands in home directory result in "i18n gem is not available" error主目录中的 Rails 命令导致“i18n gem 不可用”错误
【发布时间】:2018-06-23 15:08:29
【问题描述】:

我在我的 Ubuntu 主目录中,尝试使用 rails new 创建一个新的 rails 应用程序,但出现此错误:

i18n gem 不可用。请将其添加到您的 Gemfile 并运行 bundle install

我运行的任何 rails 命令都会出现该错误。我真的很困惑,因为我不在应用程序中。我只是在我的主目录中。没有gemfile。我尝试使用gem install 'i18n' 将“i18n”安装到我的主目录中,它成功了,但我仍然收到该错误。

我以前从未在我的主目录中遇到过关于 rails 命令的任何问题。当我 cd 进入我的个人应用程序时,所有与 Rails 相关的东西都可以正常工作。怎么回事?

另外,我现在在所有现有的 Rails 应用程序中都遇到了同样的错误。 rails 是不是突然变得依赖那个 gem 了?或者删除我的主目录中的 gem 是否会导致它在我的应用程序中不可用?


更新

我尝试gem cleanup rails 并重新安装,但没有任何改变。结果如下:

$ gem cleanup rails
  Cleaning up installed gems...
  Attempting to uninstall rails-4.0.10
  Successfully uninstalled rails-4.0.10
  Attempting to uninstall rails-4.2.1
  Successfully uninstalled rails-4.2.1
  Attempting to uninstall rails-4.2.4
  Successfully uninstalled rails-4.2.4
  Attempting to uninstall rails-5.0.1
  Successfully uninstalled rails-5.0.1
  Attempting to uninstall rails-5.0.2
  Successfully uninstalled rails-5.0.2
  Attempting to uninstall rails-5.0.3
  Successfully uninstalled rails-5.0.3
  Attempting to uninstall rails-5.0.4
  Successfully uninstalled rails-5.0.4
  Clean Up Complete
$ gem install rails -v 5.0.1
  Fetching: rails-5.0.1.gem (100%)
  Successfully installed rails-5.0.1
  Parsing documentation for rails-5.0.1
  Installing ri documentation for rails-5.0.1
  Done installing documentation for rails after 1 seconds
  1 gem installed
$ rails -v
  The i18n gem is not available. Please add it to your Gemfile and run bundle install

更新 2

我之前手动安装了i18n,我认为这可能是问题所在,所以我卸载了railsi18n,然后重新安装了rails。但我仍然收到错误:

  $ gem uninstall rails --all

You have requested to uninstall the gem:
    rails-5.0.1

browser-2.3.0 depends on rails (>= 0, development)
browser-1.1.0 depends on rails (>= 0, development)
browser-0.9.1 depends on rails (>= 0, development)
carrierwave-1.2.1 depends on rails (>= 4.0.0, development)
carrierwave-1.0.0 depends on rails (>= 4.0.0, development)
rails_serve_static_assets-0.0.5 depends on rails (>= 3.1, development)
rails_serve_static_assets-0.0.4 depends on rails (>= 3.1, development)
sass-rails-4.0.5 depends on rails (>= 0, development)
sunspot_rails-2.2.7 depends on rails (>= 3)
twitter-typeahead-rails-0.10.5 depends on rails (>= 3.1, development)
yaml_db_improved-1.0.1 depends on rails (>= 0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled rails-5.0.1

  $ gem uninstall i18n --all

You have requested to uninstall the gem:
    i18n-0.9.1

activesupport-5.1.4 depends on i18n (~> 0.7)
activesupport-5.0.5 depends on i18n (~> 0.7)
activesupport-5.0.4 depends on i18n (~> 0.7)
activesupport-5.0.3 depends on i18n (~> 0.7)
activesupport-5.0.2 depends on i18n (~> 0.7)
activesupport-5.0.1 depends on i18n (~> 0.7)
activesupport-4.2.4 depends on i18n (~> 0.7)
activesupport-4.2.1 depends on i18n (~> 0.7)
activesupport-4.0.10 depends on i18n (>= 0.6.9, ~> 0.6)
capistrano-3.8.0 depends on i18n (>= 0)
capistrano-3.7.2 depends on i18n (>= 0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled i18n-0.9.1

  $ gem install rails --version 5.0.1

Fetching: i18n-0.9.1.gem (100%)
Successfully installed i18n-0.9.1
Fetching: rails-5.0.1.gem (100%)
Successfully installed rails-5.0.1
Parsing documentation for i18n-0.9.1
Installing ri documentation for i18n-0.9.1
Parsing documentation for rails-5.0.1
Installing ri documentation for rails-5.0.1
Done installing documentation for i18n, rails after 4 seconds
2 gems installed

  $ rails -v

The i18n gem is not available. Please add it to your Gemfile and run bundle install
/home/user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:2278:in `check_version_conflict': can't activate activesupport-5.1.4, alrea
...

【问题讨论】:

  • 你能看到你的i18n gem 安装在哪里做bundle show i18n 吗?
  • @Subash 该命令返回:“无法定位 Gemfile 或 .bundle/ 目录”
  • 您的 ruby​​/rails 环境似乎有问题,您可以使用ruby -v 吗?您使用什么来管理您的 rubies,rvmrebnv
  • @Subash Yes "ruby -v" 返回 "ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]" 的预期输出。我正在使用 rvm。
  • 您是否尝试过卸载所有内容并重新安装检查

标签: ruby-on-rails ruby ubuntu rubygems rails-i18n


【解决方案1】:

再试一次gem install rails。或gem install rails -v 5.0 安装特定版本。

您似乎没有安装rails,并且它的依赖项已完全安装。也许是因为您重新安装了 ruby​​ 或安装了不同的 ruby​​ 版本。如果我是对的,那就是发生了什么,只需重新安装最新版本的 rails 或您想要的版本,所需的一切都会再次出现。

【讨论】:

  • 我跑了gem install rails -v 5.0.1,终端说它安装成功,但是任何rails命令仍然返回关于缺少i18n gem的错误,需要将它添加到我的gemfile中。
【解决方案2】:

您是否在使用任何版本管理器,rvmrbenv?您应该使用它来防止在安装库和确保您的包被订购时出现任何不匹配。

我会建议你删除任何与 Ruby 相关的东西并首先安装 Rbenv。快速搜索该错误,我发现它主要与 RVM 有关。我可能是错的,但尝试使用 Rbenv。使用 Rbenv 在你的 Ubuntu 中设置 Ruby。这是Rbenv in Ubuntu 16.04的链接

另外,为什么不尝试创建一个 Gemfile 并实际添加 gem 'i18n', '~> 0.7.0'

然后运行bundle install。如果它说它是 gem 锁定的,请使用 bundle update i18n

它说了什么?

另外,which -a ruby 有什么好处

【讨论】:

    【解决方案3】:

    您可能安装了多个版本的 rails。也许尝试运行gem cleanup rails

    有关该命令的更多信息,请参阅gem cleanup --help

    编辑:当然你必须再次安装导轨。最新的稳定版本或您喜欢的任何版本。

    更新

    查看您的 gem install 输出,它似乎没有安装任何依赖项,因此它假定您已经安装了 i18n。

    你可以这样做:

    1. 查看您安装了哪些版本。分别运行gem list | grep i18ngrep rails

    2. 分别通过gem uninstall i18n --allgem uninstall rails --all删除这些gem的所有版本

    3. 安装rails gem install rails --version 5.0.1,在安装过程中应该输出Successfully installed i18n-0.9.1

    这是我的输出:

    # blank slate
    $ rails -v
    Rails is not currently installed on this system.
    
    # successful rails install
    $ gem install rails -v 5.0.1
    ...
    Fetching: i18n-0.9.1.gem (100%)
    Successfully installed i18n-0.9.1
    ...
    35 gems installed
    
    # verify installed gems
    $ gem list | grep rails
    rails (5.0.1)
    ...
    $ gem list | grep i18n
    i18n (0.9.1)
    
    # break i18n
    $ gem uninstall i18n --all
    
    You have requested to uninstall the gem:
    i18n-0.9.1
    
    activesupport-5.0.1 depends on i18n (~> 0.7)
    If you remove this gem, these dependencies will not be met.
    Continue with Uninstall? [yN]  y
    Successfully uninstalled i18n-0.9.1
    
    $ rails -v
    /Users/me/.rvm/rubies/ruby-2.3.6/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'i18n' (~> 0.7) among 51 total gem(s) (Gem::MissingSpecError)
    
    # fix i18n and rails
    $ gem uninstall rails --all
    Successfully uninstalled rails-5.0.1
    $ gem uninstall i18n --all
    $ gem install rails --version 5.0.1
    Fetching: i18n-0.9.1.gem (100%)
    Successfully installed i18n-0.9.1
    Fetching: rails-5.0.1.gem (100%)
    Successfully installed rails-5.0.1
    2 gems installed
    
    # working again
    $ rails -v
    Rails 5.0.1
    

    【讨论】:

    • 我这样做了,起初它似乎可以工作,但是当我尝试对新安装的导轨执行任何操作时,我得到了同样的错误。我在我的问题中添加了所有输出。
    • 我尝试卸载 i18n 和 rails 并重新安装 rails,但仍然出现错误。
    【解决方案4】:

    所以我仍然不明白到底发生了什么,但我使用gem uninstall rails 卸载了rails,然后只使用gem install rails 重新安装了它,rails 命令现在可以工作了。显然这个问题甚至与 i18n 并没有真正的关系。我完全不知所措。至少现在可以了!

    【讨论】:

      【解决方案5】:

      问题在于安装ruby的地方的i8ln。

      例如

      Ruby2.3.3\lib\ruby\gems\2.3.0\gems

      尝试重新安装 ruby​​ 并尝试。

      确保在进行全新安装之前清除所有 ruby​​ 文件。

      【讨论】:

        猜你喜欢
        • 2011-05-27
        • 2015-08-26
        • 1970-01-01
        • 1970-01-01
        • 2017-04-03
        • 1970-01-01
        • 2015-01-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多