I had this problem a lot, too. Here are a few solutions:
general notes
The App Store says Xcode is 12.7 GB (13.3.1). I don't know why it says that, because:
The Xcode app is 32.5 GB, though it takes "only" 17.4 GB on disk.
I don't know what "on disk" means vs not, but it's right there if you "Get Info" on the Xcode app.
In practice, the App Store will say we don't have enough space unless we have ~46 GB free.
If you have a more precise number and/or know how to calculate it, let us know here!
(Add the Xcode app size of 32.5 + the App Store's 12.7 = 45.2?)
When upgrading Xcode, you can delete the old app version to free up space, then install the latest version.
Or safer: Copy the old Xcode app to another drive, just in case the new install fails.
Besides using the App Store, you can install/update Xcode manually. The problem with that is the App Store will then get out of sync, and thus think you don't have the latest version of Xcode, forever. This gets frustrating if you like having automatic App Store updates.
via the App Store
You can free space by moving the Xcode app to another drive (gave me 19 GB)
You can also move non-Xcode apps and big files to another drive, then move them back after Xcode installation.
Besides the Xcode app, there are related files elsewhere that could be deleted.
I found this article helpful (https://chris-mash.medium.com/saving-space-as-an-ios-developer-c09f5b6af395).
That article mentions the app "DevCleaner for Xcode":
(https://github.com/vashpan/xcode-dev-cleaner)
(https://apps.apple.com/us/app/devcleaner-for-xcode/id1388020431?mt=12)
manually via the Apple Developer download page
(https://developer.apple.com/download/applications/)
You could, for example:
Download the Xcode .xip (13.3.1 is 10 GB) and then extract it
If you don't have enough space to extract, then move the .xip to another drive and extract it there, then copy it back, overwriting the old Xcode app
Note: extracting the .xip is apparently much faster via the command line
(https://twitter.com/_saagarjha/status/1481353292164698112)
e.g., xip --expand <input-file>
"manually" with the third-party app, "Xcodes"
(https://github.com/RobotsAndPencils/XcodesApp#installation)
I tried this on my 2019 MacBook Air with its tiny 121 GB drive. (My only Mac right now.)
This actually worked really well. With the app's "Experiments" turned on, Xcode updated without me having to move or delete anything. (I had 37 GB free.)
remember
A manual solution may require less space, and could install faster. But then the App Store will always think you need to update Xcode. (Until you do update/install Xcode via the App Store.)
Having another drive is your friend and key to this! It doesn't have to be a big fancy external drive; I used a 120 GB flash drive/stick. Kinda slow, but it got the job done.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: