These installation instructions for Xcode and Homebrew have been tested and work 100% on Apple Mac OS X.
Installing Xcode on Mac
Visit this link https://apps.apple.com/us/app/xcode/id497799835?mt=12, then click View in Mac App Store. After that the Xcode page on the App Store should open automatically. Click the Free button, and then Install App.

Xcode is about 2 GB, so be prepared to wait a bit while it downloads. Once the download finishes, open Launchpad (rocket icon) and double‑click the Xcode icon – if it launches, the installation succeeded.
Installing Homebrew on Mac
Homebrew is a package installer for macOS. With it you can install hundreds of open‑source programs for Mac. To install it, enter the following command in your terminal:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
and press Enter (return). During installation you will be asked for your password; type it and press Enter again. The password is not displayed as you type, so be careful and do not rush. Once the installation completes, verify everything is ok with:
brew doctor
If the command returns Your system is ready to brew, everything is fine. If not, run the following three commands:
xcode-select --install
This command checks your Xcode and installs any necessary components.
brew update
This updates Homebrew. Then run the health check again:
brew doctor