Squeezing Xcode for hard drive space
If you’re like me you might spend a lot of your time with a maxed-out hard drive on your Mac, which is pretty frustrating!
Installing a new version of Xcode currently (at Xcode 14.3), requires ~42GB of free space, which is incredible. I’ve only got 128GB of space on my MacBook so it’s pretty damned hard to provide Xcode enough room to update.
Due to that, I’ve come across some very useful tips for reclaiming space, especially from Xcode itself.
Dev Cleaner
First up we have a great free (and open-source) app called Dev Cleaner. It’s specifically designed for those of us who use Xcode for iOS (or macOS, tvOS, watchOS or other dev) and will let you delete a load of old OS files that you probably don’t need on your machine anymore, freeing up huge amounts of space.
I think I installed it early this year and about 8 months later I’ve saved 25GB of space. I also ran it on my work MacBook Pro and saved a whopping 60GB there straight off the bat.
One tip I’ve got for Dev Cleaner is that it auto-selects (for deletion) everything but the latest version of each OS. In general, that might be fine, but if you’ve installed a beta version of Xcode then that will be your newest OS and all prior ones will be deleted, which might not be what you want, so check which OS versions are ticked before hitting the ‘Clean’ button.
From what I’ve seen being discussed about what Dev Cleaner does, the only danger of deleting older OS support files is that if you get a crash report come in for an OS that you’ve deleted then you won’t be able to symbolicate it and so it will be fairly useless to you. If you don’t deal with crash reports then delete away I guess! I think the only way to get the support files back would be to plug in a device running that OS. If you’re concerned about this then maybe just delete the OS versions you don’t support anymore.
Delete unavailable simulators
For some, maybe sensible, reason Xcode doesn’t remove old simulators that you can’t even use anymore. So you could have, for example, iOS 6 simulators still hanging around on your machine that you’re never going to use. This should definitely be something that gets built into Xcode at some point, but until then you can use the following command to automatically get rid of any unusable simulators for you:
xcrun simctl delete unavailable
Something else you can do with a similar command is remove any simulators that you really don’t need to have. Just look at all the simulators we’ve got to test an iPhone app on:
It’s great to have all those options in case you want to try something out on a device with a different screen size, but I wonder how many we actually ever use. I’m not sure there’s much benefit to having three 12.9-inch iPad Pro simulators for most people. And the all the Plus variations probably aren’t necessary. This list could be stripped down quite a lot for most people who are desperate to reclaim some hard drive space.
And don’t forget about watchOS and tvOS. If you don’t develop for those platforms you can delete those simulators and save even more space!
To delete individual, available, simulators it’s easier to do so through Xcode. Go to Window > Devices and simulators, then select the Simulators tab. You can right-click on any simulator and select ‘delete’ to get rid of it.
If you do delete any simulators that you later find you want to use you should be able to get them back from Xcode’s preferences under ‘components’, or from the Apple developer downloads site.
Incidentally, there’s a lot of extra things you can do with the ‘xcrun simctl’, Shashikant Jagtap has a nice looking writeup of this.
Delete Xcode
It’s preferable if you can just update Xcode rather than delete and re-download it again, but it’s definitely going to be taking up more than 10GB of your drive so it’s a good way of getting a chunk of space back.
If you do delete it and you still don’t have enough space then you could possibly remove the follow directory, which (for me) was ~18GB (after removing various things with DevCleaner):
Users/<username>/Library/Developer/
In there I have folders called CoreSimulator, Xcode, XCPGDevices and XCTestDevices. None of those sound relevant if you’ve just deleted Xcode, but be warned, in the Xcode folder there’s an Archives folder, which holds all your archived apps, including those you’ll have submitted to the AppStore, so you might not want to delete those.
Shrink Google Chrome
A problem I noticed with Google Chrome is that it bloats itself over time. When you first install it it probably clocks in at around the 300MB mark. Not bad. But over time it will update itself automatically and instead of replacing the new versions of itself it just caches them all within the .app so over time it can grow to quite a few gigabytes!
Well, having written that, I just went to go and get a reference shot of what this looks like and it looks like they’ve changed the internals of the .app to not have the ‘Versions’ folder where all the caching was happening (I did only recently reinstall it for some testing, though, so maybe the next update will reinstate the behaviour).
Chrome is the only app that I’ve got on my machine that was doing anything like this but there could be others so it’s something you could look into if any of your apps seem oddly large. You can right click any .app and select ‘Show Package Contents’ to explore the contents of it. Of course, you need to be careful because you’re not the developer of these apps so might not understand what the contents of the .app are for and could break it!
Check the Storage Management app
Whenever macOS gives you a low hard drive space warning it prompts you to ‘manage’ your storage in the Storage Management app.
It’s a great app that lists all the heavy apps and files on your machine so if you’re desperate for space you can go and pick off some of the larger ones to get the space down quickly.
Maybe there are some apps you really don’t need. Currently I’ve got Garage Band using up 2.36GB for loads of sound packs and such, as well as 1.06GB for the app itself. I’m pretty sure that all came preinstalled so if you’re not likely to use it get rid of it and save yourself nearly 3.5GB!
Restart your Mac!
I’ve had some big disk space gains by simply restarting my MacBook. A recent example resulted in the Storage Management app reporting an additional 3GB of space! Who knows where that space might have come from, but it’s certainly welcome!
I’ve got a feeling that the Mac and/or App Store app don’t always recheck available space once you’ve freed some up, rather they’re looking at a cached value for the free space. I swear sometimes just restarting the Mac (without it reporting any additional free space) has resulted in the App Store happily starting the download…
Further reading
Ajith R Nayak has a nice looking write up on some of the places you can save space with Xcode, some of these are certainly covered by Dev Cleaner but it looks like there’s some extra places to check, especially if you’ve been using the same machine for a long time (i.e. before iOS 6).
There’s even an article on Hacking With Swift where Paul Hudson covers some similar areas for saving space.
I’d love to hear about any other tips for saving space so leave a comment if you’ve got something I’ve missed!