In your Mac, open the "App Store":

On the search icon type "Xcode":

Click on "Get" and follow the prompts in order to install the software.