主目录中的Rails命令导致“i18n gem not available”错误

时间:2018-01-14 23:45:55

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

我在我的Ubuntu主目录中,试图用rails new创建一个新的rails应用程序,但是我收到了这个错误:

  

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

我运行的任何rails命令都会出错。我真的很困惑,因为我不在应用程序中。我就在我的主目录中。没有gemfile。我尝试使用gem install 'i18n'将'i18n'安装到我的主目录中,但它确实有效,但我仍然遇到了这个错误。

之前我的主目录中的rails命令从未遇到过任何问题。当我cd进入我的个人应用程序时,与导轨相关的所有内容都能正常工作。发生了什么事?

,我现在在所有现有的rails应用中遇到同样的错误。铁轨突然变得依赖于那颗宝石了吗?或者可以删除我的主目录中的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
...

5 个答案:

答案 0 :(得分:5)

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

看起来你似乎没有完全安装了rails和它的依赖项。也许是因为你重新安装了ruby或安装了不同的ruby版本。如果我说的是正确的,只需重新安装最新版本的rails或您想要的版本,所需的一切将再次出现。

答案 1 :(得分:2)

您使用的是任何版本管理器rvm还是rbenv?您应该使用它来防止安装库中的任何不匹配并确保订购包。

我建议您删除任何与Ruby相关的内容并首先安装Rbenv。快速搜索该错误,我发现它主要与RVM有关。我可能错了,但尝试用Rbenv。使用Rbenv在Ubuntu中设置Ruby。以下是Rbenv in Ubuntu 16.04

的链接

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

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

它说什么?

此外,您使用which -a ruby

得到了什么?

答案 2 :(得分:1)

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

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

编辑:当然,你必须再次安装rails。无论是最新的稳定版还是您喜欢的版本。

<强>更新

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

以下是您可以做的事情:

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

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

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

  4. 这是我的输出:

    # 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
    

答案 3 :(得分:1)

所以我仍然不能确切地了解发生了什么,但是我使用gem uninstall rails卸载了rails,然后使用gem install rails重新安装了它,现在rails命令正常工作。显然这个问题甚至与i18n无关。我完全失败了。至少它现在有效!

答案 4 :(得分:0)

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

例如

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

尝试重新安装ruby并尝试。

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