In your Terminal, type:
xcode-select --install
This opens a window with a prompt. Follow the prompts. It then takes about 10 min to install.
Confirm that Xcode is installed:
Any of these methods will work:
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version
# version: 14.2.0.0.1.1668646533
or
xcode-select -p
# /Library/Developer/CommandLineTools
or
gcc --version
# Apple clang version 14.0.0 (clang-1400.0.29.202)
# Target: arm64-apple-darwin22.3.0
# Thread model: posix
# InstalledDir: /Library/Developer/CommandLineTools/usr/bin