My computer has been getting low on hard drive space and I thought it might be a good time to clean up after XCode. A few simple tasks gave me back over 60 gigabytes of wasted XCode files.
Derived Data
The simplest task is to remove the folders inside the DerivedData folder that XCode uses to profile projects.
The DerivedData folder might be located at ~/Library/Developer/XCode/DerivedData
If the folder is non-existent or it is empty and you have opened at least one XCode project, the DerivedData folder might be set to a different location. Open XCode and click XCode > Preferences. Navigate to the Locations tab on the top right and locate the Derived Data section. Click on the small arrow to reveal the folder in the finder.
Delete the folders inside the DerivedData folder. This alone gave me back over 30 GBs. In the below example there are only two folders inside DerivedData, so in this case delete those two folders.
Remove XCode Build Folders
XCode makes build folders to store files to speed up compilation times. If you are no longer working with the project, you won’t need faster compile times, so you should get that HD space back.
We can use the find command to locate all directories with the name build and delete them, but only before asking. This post breaks down the command. The command is
find . -type d -name 'build' -ok rm -rf {} \;
The . tells the command to traverse the hierarchy starting with the current folder. -type d limits the search to directories and the -ok asks before executing the code to the right of it. Make sure to navigate to the folder you wish to start with using cd. For example, executing
cd ~/Documents/myprojectfolder/
and then executing
find . -type d -name 'build' -ok rm -rf {} \;
would find all directories with the name build in the myprojectfolder and its children. For every directory it finds, it will ask if it should delete it. Type y
for yes and n
for no.
Keep in mind that if you choose to delete the folder, it will also remove all of its contents. So if you have another folder that is named build, make sure it is one that you want to delete!