Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

When I want to create a Ruby on Rails project, I get the message below.

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'     from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support.rb:57     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'     from /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails_generator.rb:31     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'     from /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails:15     from /usr/bin/rails:19:in `load'     from /usr/bin/rails:19

What has gone wrong? How do I to fix it?

回答1:

This is an incompatibility between Rails 2.3.8 and recent versions of RubyGems. Upgrade to the latest 2.3 version (2.3.11 as of today).



回答2:

In case you can't upgrade to Ruby on Rails 2.3.11 (and to expand on douglasr's answer), thread must be required at the top of boot.rb. For example:

require 'thread'  # Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb ...


回答3:

I was able to fix this by downgrading RubyGems to 1.5.3, since it happens with RubyGems 1.6.0+ and Rails < 2.3.11:

gem update --system 1.5.3

If you had previously downgraded to an even earlier version and want to update to 1.5.3, you might get the following when trying to run that:

Updating RubyGems ERROR:  While executing gem ... (RuntimeError)     No gem names are allowed with the --system option

If you get that error, then update, so that it lets you specify the version, and then downgrade again:

gem update --system gem update --system 1.5.3


回答4:

You can also likely get around this issue by requiring 'thread' in your application as such:

require 'thread'

As per the RubyGems 1.6.0 release notes.



回答5:

If you want to keep your version same like rails will be 2.3.8 and gem version will be latest. You can use this solution Latest gem with Rails2.x. in this some changes in boot.rb file and environment.rb file.

require 'thread' in boot.rb file at the top.

and in environment.rb file add the following code above the initializer block.

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.3.7')  module Rails    class GemDependency      def requirement        r = super        (r == Gem::Requirement.default) ? nil : r      end    end  end end


回答6:

I have faced this problem in many occassions when I try to start an old rails 2.3.5 project after having worked with rails 3>. In my case to solve the problem, I must do a rubygems update to version 1.4.2, this is:

sudo gem update --system 1.4.2


回答7:

If you're using Radiant CMS, simply add

require 'thread'

to the top of config/boot.rb.

(Kudos to Aaron's and nathanvda's responses.)



回答8:

As mentioned this occurs when using RubyGems 1.6.0 with Ruby on Rails version earlier than version 3. My app is using Ruby on Rails 2.3.3 vendored into the /vendor of the project.

No doubt an upgrade of Ruby on Rails to a newer 2.3.X version may also fix this issue. However, this problem prevents you running Rake to unvendor Ruby on Rails and upgrade it.

Adding require 'thread' to the top of environment.rb did not fix the issue for me. Adding require 'thread' to /vendor/rails/activesupport/lib/active_support.rb did fix the problem.



回答9:

Try updating your Ruby on Rails version to v3.0.5:

gem install rails --version 3.0.5

or v2.3.11:

gem install rails --version 2.3.11

If this isn't a new project you'll have to upgrade your application accordingly. If it was a new project, just delete the directory you created it in and create a new project again.



回答10:

update the rubygems

gem update --system



回答11:

I'm posting my solution for the other sleep-deprived souls out there:

If you're using RVM, double-check that you're in the correct folder, using the correct ruby version and gemset. I had an array of terminal tabs open, and one of them was in a different directory. typing "rails console" produced the error because my default rails distro is 2.3.x.

I noticed the error on my part, cd'd to the correct directory, and my .rvmrc file did the rest.

RVM is not like Git. In git, changing branches in one shell changes it everywhere. It's literally rewriting the fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!