Can I safely delete contents of Xcode Derived data folder?
Asked Answered
H

12

347

I am running low on disk space and checked through a third party utility that among other things that ~/Library/Developer/Xcode/DerivedData directory is taking about 22GB of disk space.

I searched stackoverflow and found this post

How can I safely delete in my ~/Library/Developer/Xcode/DerivedData directory?

The accepted answer to this question suggests that I should not touch / remove folders from this directory. so what I did was

  • Found an existing build project folder for an app that I have available on Appstore
  • Deleted the folder from derived dir
  • launched XCode 5
  • Open that project
  • Clean Build
  • Tested and compiled it on a simulator
  • ReArchived
  • Everything worked. Nothing was broken.

Unless I missed something in that posts answer I want to make sure by asking experienced developers that if I delete all the folders from DerivedData it will not hurt me in building, testing and compiling those projects.

Hamza answered 21/9, 2013 at 13:46 Comment(1)
accepted answer to the referenced question is https://mcmap.net/q/17076/-how-can-i-safely-delete-in-my-library-developer-xcode-deriveddata-directory which doesn't say anything about not deleting from DerivedData... though Archives is important to debug stuff later, but that's a different directory.Stolon
N
423

Yes, you can delete all files from DerivedData sub-folder (Not DerivedData Folder) directly.

That will not affect your project work. Contents of DerivedData folder is generated during the build time and you can delete them if you want. It's not an issue.

The contents of DerivedData will be recreated when you build your projects again.

Xcode8+ Update

From the Xcode8 that removed project option from the window tab so you can still use first way:

Xcode -> Preferences -> location -> click on small arrow button as i explain in my first answer.

Xcode7.3 Update For remove particular project's DeriveData you just need to follow the following steps:

Go to Window -> Project:

enter image description here

You can find the list of project and you can either go the DerivedData Folder or you can direct delete individual Project's DerivedData

enter image description here


I am not working on Xcode5 but in 4.6.3 you can find DerivedData folder as found in the below image:

enter image description here

After clicking on Preferences..

enter image description here

You get this window

enter image description here

Noe answered 21/9, 2013 at 13:51 Comment(5)
Thanks a lot man. Is "Derived Data" contents basically just like Xcode's cached and unwanted files? So that'd why its ok to delete it to clear space?Ramses
@gone What are you talking about? The built files have to go somewhere.Trainer
Well, with CMake and other make systems, even with out-of-source builds, the generated files etc are still inside the project's path, and are deleted if I delete the folder structure or cleaned when I perform a clean. Since I am marking approx 100 assignments every week or so, I get a huge build up of files that I need to remember to manually delete, and using the XCode UI, each project's data individually. So I stand by my previous comment, though I've now implemented William's alias in my .bashrc.Sombrous
XCode 8 changes things again (it always has been pain in arse). Now, we need to manually go to the folder at /Users/YourUsername/Library/Developer/Xcode/DerivedData and delete them all. As you have had edited for XCode 7, I thought you might want to edit it again for XCode 8.Incombustible
you can check my full answer there is multiple answer in same old one still working to go preferance and from location tab. :)Noe
W
137

I purge derivedData often enough that I have an alias for it. It can fix build problems. I have the following in /Users/Myusername/.bash_profile

alias purgeallbuilds='rm -rf ~/Library/Developer/Xcode/DerivedData/*'

Then in terminal, I type purgeallbuilds, and all subfolders of DerivedData are deleted.

Willner answered 21/9, 2013 at 14:1 Comment(3)
You can delete the DerivedData folder itself. It will just be re-created.Gastight
Build immediately fails in Xcode 8 when I deleted this folder. Once I added it back things worked again.Omnifarious
This is very useful tip. I usually run into space shortage every half year and it's kind of hard to remember which folders should be purged. The alias is definitely convenient.Casillas
E
48

XCODE 12 UPDATE

On the tab:

  1. Click Xcode
  2. Preferences
  3. Locations -> Derived Data

You can access all derived data and clear by deleting them.

Erymanthus answered 5/10, 2016 at 6:46 Comment(2)
The Derived Data section only defines the path of the derived data. I dont see anywhere to view and delete them. Why not just do it via command line?Sensitize
@Sensitize At the end of the path address, you will see an icon that will take you to folder. Tap on it and delete the folder and it will be re-created.Erymanthus
U
34

XCODE 7.2 UPDATE

(Also works for 7.1.1)

  1. Click Window then Projects and then delete Derived Data.

Like this:

enter image description here

And then delete it here:

enter image description here


Hope that helps!

Unperforated answered 16/11, 2015 at 13:5 Comment(1)
This will enable you to delete it manually one by one but the means used in other posts are for deleting the DerivedData folder contents at onceEpanodos
A
25
 $ du -h -d=1 ~/Library/Developer/Xcode/*

shows at least two folders are huge:

 1.5G   /Users/horace/Library/Developer/Xcode/DerivedData
 9.4G   /Users/horace/Library/Developer/Xcode/iOS DeviceSupport

Feel free to remove stuff in the folders:

 rm -rf ~/Library/Developer/Xcode/DerivedData/*

and some in:

 open ~/Library/Developer/Xcode/iOS\ DeviceSupport/
Anderson answered 17/9, 2015 at 4:50 Comment(1)
holy crap... deleting the files from older versions of iOS in device support folder freed up 28GB...Crick
J
18

Just created a github repo with a small script, that creates a RAM disk. If you point your DerivedData folder to /Volumes/ramdisk, after ejecting disk all files will be gone.

It speeds up compiling, also eliminates this problem

xc-launch repo

Best launched using DTerm

Jenifferjenilee answered 31/12, 2013 at 19:1 Comment(0)
P
12

XCode 8: To delete derived data for your current project:

Click Product menu

Hold Option key

Click Clean Build Folder

Per answered 28/1, 2017 at 12:15 Comment(1)
When i hold the option key the Clean Build option is grayed out. :/Sensitize
T
4

XCODE 10 UPDATE

Click to Xcode at the Status Bar Then Select Preferences

In the PopUp Window Choose Locations before the last Segment

You can reach Derived Data folder with small right icon

enter image description here

Tailspin answered 18/9, 2018 at 11:5 Comment(0)
V
3

~/Library/Developer/Xcode/DerivedData

Vigilance answered 14/6, 2016 at 11:0 Comment(1)
By default yes; I use ~/tmp/DerivedData so I can get to the built files/bundles easier.Trainer
N
1

yes, safe to delete, my script searches and nukes every instance it finds, easily modified to a local directory

#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\n\t'

for drive in Swap Media OSX_10.11.6/$HOME
do
   pushd /Volumes/${drive}  &> /dev/null
   gfind . -depth -name 'DerivedData'|xargs -I '{}' /bin/rm -fR '{}'
   popd &> /dev/null
done
Nepos answered 25/12, 2016 at 8:31 Comment(0)
O
-1

I would say it's safe--I often delete the contents of the folder for many kind of iOS projects, this way. And, I haven't had any issues with builds or submitting to the App Store. The procedure deletes derived data and cleans a project's cached assets, for both Xcode 5 and 6.

Sometimes, simply calling rm -rf on the Derived Data directory leaves a lingering file or two, but my script loops until all files are deleted.

Octagon answered 16/1, 2015 at 6:52 Comment(3)
Ugh. Typo. I meant 'provide'Pomiferous
Ah, I'm linking to the script I provided in an answer to another question. This way, if I ever want to update the script, I only need to edit in one place. Can you follow the link?Octagon
I see the code now. Didn't see the link before (if it was there) thanks.Pomiferous
E
-1

The content of 'Derived Data' is generated during Build-time. You can delete it safely. Follow below steps for deleting 'Derived Data' :

  1. Select Xcode -> Preferences..

Step 1

  1. This will open pop-up window. Select 'Locations' tab. In Locations sub-tab you can see 'Derived Data' Click on arrow icon next to path.

Step 2

  1. This will open-up folder containing 'Derived Data' Right click and Delete folder.

Step 3

Earldom answered 10/2, 2015 at 14:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.