The reason you are seeing this error is that your system doesn't have Xcode installed. Either you have never installed it on your Macbook or it got uninstalled during any OS update.
So to fix this issue, install Xcode. If you are into iOS App development, you can install the complete version and it will solve this issue as well. Download Xcode .dmg file from the Apple developers page.
If you don't use it, like me, you can simply search for the Command Line Tools package for Xcode and download the .dmg file for it and install it. You can download it from the Apple developers page.
If you don't want to download anything and just want to run some commands in the terminal to fix this issue, then here's the command for you:
This is the command which can be run in the terminal and will install the command line tools for Xcode. When you run this command you will be prompted to accept the license, agree with the terms and conditions, etc.
If you are shown that the download requires 7GB+ of space, then be aware you are being forced to download the Xcode Application, in that case, download the .dmg file for command line tools package specifically from the apple developer page.
The above command should fix the issue if it doesn't run the following command too:
Although this will fix your issue, as a follow-up step, you may need to set the path for the command line tools to run without Xcode.
xcode-select --switch /Library/Developer/CommandLineTools
If you face permission issues while running any of the above commands, use
sudo with the commands. For example,
sudo xcode-select --switch /Library/Developer/CommandLineTools
If you have the Xcode app installed, then try running the following command:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
This issue can happen post OS upgrade and can make services that were running well before, useless. But the above solution should fix the error that you are facing. If none of this works for you, feel free to share your error message in the comment section below.