LoadError: Could not load the 'listen' gem (Rails 5)
If you are on rails 5 and you are using the default config/environments/development.rb file it will have this line of code in there.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This requires the gem listen. This threw me for a bit as I was doing a rails 4 upgrades to a rails 5
edit: Forgot to mention that if you comment that line of code out it will not need the listen gem anymore.
You might by mistake have set bundle install --without
at some point, I sure did anyways.
To revert this run:
bundle config --delete without
I also ran bundle config --delete with
as I manually set with
option as well by mistake. Running both should get you back to default behaviour.
After having deleted the without
config I could successfully run a bundle install
again and afterwards my rails s
, rails db:migrate
etc. worked.
You can confirm if this is your issue by running bundle install
and look at the second last line in the output. If it states:
Gems in the groups development and test were not installed.
It's for sure above solution should work for you.
I used this: bundle install --without development
Error:
Could not load the 'listen' gem. Add
gem 'listen'
to the development group of your Gemfile (LoadError)
After this, use that code:
bundle config --delete without
bundle config --delete with
Finally
bundle install
I'm posting this as an answer, but I don't like it.
I can "fix" the problem by putting gem 'listen', '~> 3.1.5'
in the global Gemfile (and removing it from :development
). Then all the errors go away and everything works, but that seems wrong.
I'm having the same problem by running rails c
.
By reading this other Stack Overflow post I did realize that it is normal that both bundle exec rake
command or rails console
are running in a default production
environment.
I figured I will solve the issue either by:
- adding
export RAILS_ENV=production
in ~/.bash_profile - explicitly writing the environment in which I want the command to execute like
bundle exec rake a_rake:task RAILS_ENV=production
rails console --env=production
etc...