ruby-on-rails 主目录中的Rails命令导致“i18n gem is not available”错误

ybzsozfc  于 2022-12-20  发布在  Ruby
关注(0)|答案(6)|浏览(201)

我在我的Ubuntu主目录中,尝试使用rails new创建一个新的rails应用程序,但是我收到了这个错误:
i18n gem不可用。请将其添加到gem文件中,然后运行捆绑安装
我运行的任何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
...
wecizke3

wecizke31#

请重试gem install rails。或使用gem install rails -v 5.0安装特定版本。
看起来你好像没有完全安装rails和它的依赖项.可能是因为你重新安装了ruby或者安装了一个不同的ruby版本.如果我是对的,只要重新安装最新版本的rails或者你想要的版本,所有需要的东西都会再次出现.

mutmk8jj

mutmk8jj2#

您使用的是版本管理器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可以得到什么

rqqzpn5f

rqqzpn5f3#

您可能安装了多个版本的rails。可以尝试运行gem cleanup rails
有关该命令的详细信息,请参见gem cleanup --help
编辑:当然你还得重新安装rails,最新的稳定版本或者你喜欢的版本。

    • 更新**

查看gem install的输出,它似乎没有安装任何依赖项,因此它假设您已经安装了i18n。
以下是您可以执行的操作:
1.检查您安装的版本。分别运行gem list | grep i18ngrep rails
1.分别通过gem uninstall i18n --allgem uninstall rails --all删除这些gem的所有版本
1.安装导轨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
tcomlyy6

tcomlyy64#

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

ahy6op9u

ahy6op9u5#

问题出在安装ruby的地方的i8ln上。
例如
第一个月
尝试重新安装ruby并尝试。
确保在进行全新安装之前清除所有ruby文件。

tktrz96b

tktrz96b6#

在一个rails www.example.com项目上进行了一次混乱的合并后,我也遇到了同样的错误6.1.4.7。
我运行了gem uninstall rails,在Gemfile中将rails版本切换到7.0.4,然后运行了bundle update,之后,所有的rails命令似乎都工作正常。

相关问题