いつも通りrails sをしたら上記のエラーが出たので解決方法を載せておきます
現在動いてるRubyのプロセスを確認
$ ps -ax | grep ruby
このように表示される
49551 ?? 0:00.00 /Users/UserName/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rb-fsevent-0.11.1/bin/fsevent_watch --format=otnetstring --latency 0.1 /Users/UserName/Rails_product/you_conect/config/locales
49552 ?? 0:00.00 /Users/UserName/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rb-fsevent-0.11.1/bin/fsevent_watch --format=otnetstring --latency 0.1
動いてるプロセスを終了する
例: kill 49551
$ kill ポート番号
それでも終了できない場合は強制終了
$ kill -9 ポート番号
これで普通はうまくいくはず
しかし自分の場合はこれでも上手くいかなかった
$ rails s
エラー文
(Address already in use - bind(2) for "127.0.0.1" port 3000 )
そこでport3000を使ってるのを検索する
$ lsof -i :3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 24955 UserName 26u IPv4 0xae9f2b2917715115 0t0 TCP localhost:hbci (LISTEN)
このように使われているのがあったため
$ kill 24955
再度 rails sをしたら上手く動いた
$ rails s
=> Booting Puma
=> Rails 6.1.6 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 3.1.0-p0) ("Birdie's Version")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 48888
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop
最終手段
めんどくさい時や上記の方法で解決しないときはPCを再起動しましょう
要は裏で動いてるのを再起動で、真っ白にするイメージです。
これで解決