Reload the shotgun! — Shotgun error- “port is in use or requires root privileges (RuntimeError)”.

To use/start Ruby as a back-end server you will need to use something called “Shotgun” but why would I need a shotgun to start my server you asked? Well.. is not what you are thinking.

What is Shotgun?

Shotgun is a Ruby gem that allows you to have a local server running to test Ruby web applications.

When you run or type “shotgun” in your terminal, Shotgun will reload your application upon every request. Which means every time you change your code, you can hit ‘Refresh’ in your browser and see the changes you recently made.

While working with Ruby and using it as a back-end I encountered the error below, which in short says that shotgun cannot run/start because the “Shotgun” server is already running somewhere. If you have another terminal open running it, simply kill it or shut it down by typing CTRL+C. If for some reason you can’t find the terminal or do not know where “Shotgun” is running, I have a solution for you.

Error: “port is in use or requires root privileges (RuntimeError)”.

== Shotgun/Thin on http://127.0.0.1:9393/2021–07–14 18:04:57 -0400 Thin web server (v1.8.1 codename Infinite Smoothie) 2021–07–14 18:04:57 -0400 Maximum connections set to 1024 2021–07–14 18:04:57 -0400 Listening on 127.0.0.1:9393, CTRL+C to stop Traceback (most recent call last):

/Users/jayson/.rvm/gems/ruby-2.7.2/gems/eventmachine-1.2.7/lib/eventmachine.rb:531:in `start_tcp_server’: no acceptor (port is in use or requires root privileges) (RuntimeError)

Let start by typing the following in your terminal- ps aux | grep ruby. This will show you the other ports that are using a “Shotgun”. As you can see below, I have one that started it at 10:30am [3875] and the one I am trying to run at 6:08pm [25128].

jayson 3875 0.0 0.1 4481160 16392 s001 S+ 10:30AM 0:04.79 ruby /Users/jayson/.rvm/gems/ruby-2.7.2/bin/shotgun jayson 25128 0.0 0.0 4268464 772 s006 S+ 6:08PM 0:00.00 grep ruby

In order to fix our error we will need to kill one. Let’s kill the oldest one running, in this case -10:30am <PID> = [3875]- If you just type kill — 3875. You will encounter the error below. This is just telling you that you need the signal name before you use the <PID>.

~$kill — 3875

kill: -: signal name expected

If you just type [~kill -9]. You will get the following error. Which as the error states you are missing the arguments, which again is <PID> = [3875].

So what is it that I NEED to do in order to fix this error!?

You can use one of the two commands below:

Kill — 9 <PID> or Kill -QUIT <PID>

[kill -9 3875 or kill -QUIT 3875]- As you can see in the screenshot below I used kill -QUIT 3875.

Once that’s done, try running “Shotgun” again and you should see your server starting to run!

Software Engineer based in NYC