Install the Xcode command line tools if you don’t need a full install of Xcode.
If you need Xcode command line tools without the HUGE Xcode application and environment, the preferred alternative for many developers is to simply install the Xcode command line tools like this:
xcode-select --install
When you run that command from the Terminal, a macOS software installation pop-up will appear asking you to install the Xcode command line tools. Of course, go ahead and install those.
And when that is done, try sudo port
again. It should be working as expected.
The Xcode command line tools are basically just the core basics Xcode needs to operate from the command line. It’s the same command line tools you would get from a full Xcode install, but in a much smaller—and in my humble opinion—more reasonable package.
Homebrew is—in my humble opinion/experience—the better and more stable macOS package installer; opt for that over MacPorts methods if possible.
If that doesn’t work, I would recommend you undo what you have done, install Xcode again, uninstall pretty much all of the tools you installed with MacPorts and ditch MacPorts as well. Instead I would highly recommend installing and using Homebrew instead.
Homebrew is a package installer/management system for macOS—much like MacPorts—but in my experience it is cleaner, easier to use and understand and much better supported.
In fact, this answer on Stack Exchange seems to address your requirements of getting cairo
install in macOS but using Homebrew.
Can your question be simplified in any way? Your question title is this, “Package installation tools - e.g. Xcode and MacPort.” But then you state, “Long story short - can someone explain how these are related?” and provide a list of items. I posted an answer explaining how to solve this issue—which I believe to be the issue of you removing Xcode and then having things fail—but now I am not too sure what you are concerned about with this question.
– JakeGould – 2018-06-02T16:10:09.650