Nowadays it is not necessary to download and install the full XCode package, it is enough to install the command line tools - exactly the tools we are interested in.
To install the command line tools, after you have installed the free XCode app, run the following command in a terminal window:
sudo xcode-select --install
and follow the on-screen instructions.
If you would like to install the full XCode package for other reasons, you get it via the Mac App Store.
Remember to open it after installation, and accept the license. Nothing XCode related will work before you have done that.