Homebrew not detecting latest Xcode and Command Line Tools, and not uninstalling them either

I have macOS Mojave version 10.14.5 installed with Xcode version 10.2.1 and Command Line Tools installed using xcode-select --install. All problem started when I tried to install youtube-dl formula on my system by running:

brew install youtube-dl

The output I get is:

Updating Homebrew...
Error: Your Xcode (1) is too outdated.
Please update to Xcode 9.0 (or delete it).
Xcode can be updated from
  https://developer.apple.com/download/more/

Error: Your Command Line Tools are too outdated.
Update them from Software Update in the App Store.

Again, if I run xcode-select --install, I get:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Running:

xcode-select -v

returns

xcode-select version 2354

(I do not know what this means) and running:

xcode-select -p

yields

/Applications/Xcode.app/Contents/Developer

Owing to these issues, I tried to uninstall Homebrew (with a plan to reinstall it afresh) by running the command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

but it gives the following error:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out

Next, I tried to uninstall Homebrew using the unbrew.rb script available at GitHub but it seems not to remove Homebrew. I tried running it with and without sudo. Even after doing this, running brew config returns:

HOMEBREW_VERSION: 1.3.2
ORIGIN: https://github.com/Homebrew/brew
HEAD: 751334a257d81851e68da7ab390982d4e9fdf909
Last commit: 1 year, 10 months ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 3fd7a855a1a357654a4a9a455162761841a4809d
Core tap last commit: 1 year, 10 months ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/Homebrew
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: quad-core 64-bit broadwell
Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: N/A
Git: 2.20.1 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Perl: /opt/local/bin/perl => /opt/local/bin/perl5.24
Python: /usr/bin/python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Java: N/A
macOS: 10.14.5-x86_64
Xcode: 1 => /Applications/Xcode.app/Contents/Developer
CLT: N/A
X11: N/A
MacPorts/Fink: /opt/local/bin/port

Running brew doctor outputs the following:

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: Your Command Line Tools are too outdated.
Update them from Software Update in the App Store.

Error: Unrecognized Mach-O load command: 0x32

Is my Homebrew broken by my attempts at uninstalling it? What can I do to repair Homebrew and all these errors in pointing to the right Xcode and command line tools?

I had tried updating Homebrew by running brew update earlier without success. Running:

brew update

returns:

fatal: unable to access 'https://github.com/caskroom/homebrew-cask/': Failed to connect to github.com port 443: Operation timed out
fatal: unable to access 'https://github.com/Homebrew/brew/': Failed to connect to github.com port 443: Operation timed out
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': Failed to connect to github.com port 443: Operation timed out
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
Fetching /usr/local/Homebrew failed!
Fetching /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask failed!

As is evident from the output of brew config, your installation of Homebrew is pretty outdated. Also, as mentioned in your comment, you have a proxy active in your system. This explains why Homebrew installation is failing to connect unable to the Homebrew software's server counterpart via port 443, which hosted on GitHub.

Follow the instructions in the following answer to update your installation of Homebrew to current version:

  • https://apple.stackexchange.com/a/232770/279727

If you run into an error similar to:

Error: Permission denied

Run:

sudo chown -R `whoami`:admin /usr/local/share

to resolve it.

If you get the following error:

Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like so: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile

Run the command-line mentioned in the last line.

Once you have Homebrew updated, run brew cleanup to remove any broken symlinks.

The current public version of Homebrew is 2.1.6. You can check if your installation of Homebrew is up-to-date by running brew config and matching the value with the HOMEBREW_VERSION: key in the output.