[ruby-on-rails] Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

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?

This question is related to ruby-on-rails rubygems compatibility

The answer is


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

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

update the rubygems

gem update --system


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 files in question. RVM, on the other hand, is just setting shell variables, and must be set for each new shell you open.

In case you're not familiar with .rvmrc, you can put a file with that name in any directory, and rvm will pick it up and use the version/gemset specified therein, whenever you change to that directory. Here's a sample .rvmrc file:

rvm use 1.9.2@turtles

This will switch to the latest version of ruby 1.9.2 in your RVM collection, using the gemset "turtles". Now you can open up a hundred tabs in Terminal (as I end up doing) and never worry about the ruby version it's pointing to.


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.)


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

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.


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
...

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.


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.


Examples related to ruby-on-rails

Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Where do I put a single filter that filters methods in two controllers in Rails Empty brackets '[]' appearing when using .where How to integrate Dart into a Rails app Rails 2.3.4 Persisting Model on Validation Failure How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? Rails: Can't verify CSRF token authenticity when making a POST request Uncaught ReferenceError: React is not defined

Examples related to rubygems

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting You don't have write permissions for the /var/lib/gems/2.3.0 directory Can't install gems on OS X "El Capitan" How to avoid "cannot load such file -- utils/popen" from homebrew on OSX How can I set a proxy server for gem? How to install CocoaPods? Error while installing json gem 'mkmf.rb can't find header files for ruby' How to downgrade or install an older version of Cocoapods

Examples related to compatibility

Which TensorFlow and CUDA version combinations are compatible? IE11 Document mode defaults to IE7. How to reset? Internet Explorer 11 disable "display intranet sites in compatibility view" via meta tag not working Possible to restore a backup of SQL Server 2014 on SQL Server 2012? How to set IE11 Document mode to edge as default? Is it possible to run a .NET 4.5 app on XP? I want to get Year, Month, Day, etc from Java Date to compare with Gregorian Calendar date in Java. Is this possible? Fragments onResume from back stack Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) How to run multiple Python versions on Windows