Listen error: unable to monitor directories for changes
Ruby on-RailsRubyUbuntuRuby on-Rails Problem Overview
I am getting the following error while running my rails app in Ubuntu server
> FATAL: Listen error: unable to monitor directories for changes. Visit > https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers > for info on how to fix this.
I have followed the above GitHub page, but I was unable to write in max_user_watches which were set in 8192 and I want to set that to 524288.
in cat /proc/sys/fs/inotify/max_user_watches
the file was in only read mode.I tried to grant write permissions, but I was getting permission denied error even with root access.
Thanks in Advance!!!
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
1000 is way too small, try with 524288 as explained in the wiki page: https://github.com/guard/listen/blob/master/README.md#increasing-the-amount-of-inotify-watchers
> Listen uses inotify by default on Linux to monitor directories for > changes. It's not uncommon to encounter a system limit on the number > of files you can monitor. For example, Ubuntu Lucid's (64bit) inotify > limit is set to 8192.
and
> If you are running Debian, RedHat, or another similar Linux > distribution, run the following in a terminal: > > echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p > > > If you are running ArchLinux, run the following command instead > > echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
Solution 2 - Ruby on-Rails
Just try to execute this from your console
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Hope this will work for you .
References: https://prashantrorblog.wordpress.com/2016/05/28/fatal-listen-error-unable-to-monitor-directories-for-changes/">click here
Solution 3 - Ruby on-Rails
For others who may have this issue. I had a VM disconnect which left the previous rails server running. Running below resolved the issue without needing to up the number of watcher.
kill -9 $(lsof -i tcp:3000 -t)
Solution 4 - Ruby on-Rails
In my case, I just need to turn off the terminal and then start it back again. It works when I try to run rails c
command :)
Solution 5 - Ruby on-Rails
This error occurred for me as I had a number of ruby processes currently running that I was unaware of. Just need to terminate them and all is good
Solution 6 - Ruby on-Rails
I had this issue during development while running rake
(even with rake -h
), and the solution from https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers did not work, neither did killing the running ruby processes, killing the terminal or even restarting the computer.
To avoid this error I did a new and clean clone of my project and then rake
was working (maybe git clean -fdx
could have worked but I did not try it).
I was running rake version 13.0.3, rails 6.1.1, ruby 2.7.2p137.
Solution 7 - Ruby on-Rails
Adding to @mayur-shah's answer,
It worked for me after closing the server and console. So, if you are running rails server/console, close that first.
Solution 8 - Ruby on-Rails
Deleting Gemfile.lock and running 'bundle' in the project directory terminal worked for me.