How to cleanly uninstall Xcode?

To cleanly uninstall Xcode from a macOS system, the definitive and officially supported method is to delete the Xcode application bundle from the `/Applications` directory using Finder or the command line, as this single action removes the core application and its bundled resources. Apple designs Xcode to be largely self-contained within its `.app` bundle, meaning the primary installation does not scatter a significant number of supporting files or libraries across the system in the manner of many traditional applications. This approach is distinct from using a third-party uninstaller or manually hunting for potential preference files, which is generally unnecessary for this specific developer tool. The simplicity of this process is intentional, ensuring developers can manage multiple versions of Xcode by simply having different application bundles, such as `Xcode.app` and `Xcode_14.2.app`, residing in the Applications folder without system-level conflicts.

However, a truly clean uninstall for advanced users or those troubleshooting persistent issues often involves removing additional data and caches that are generated *during the use* of Xcode, not by its installation. These supporting files reside in user-specific library folders and are not deleted when the app bundle is trashed. Key locations include `~/Library/Developer/`, which contains simulators, derived data, archives, and device support files; `~/Library/Caches/com.apple.dt.Xcode`; and `~/Library/Preferences/com.apple.dt.Xcode.plist`. Removing the `~/Library/Developer` directory is particularly impactful, as it can reclaim tens of gigabytes of storage used by simulator runtimes and build artifacts. This step is not required for a basic reinstall but is crucial for resolving corrupted toolchains or clearing out obsolete simulator data.

The mechanism for a thorough uninstall, therefore, follows a two-tiered strategy: first, delete the main application, and second, selectively remove generated user data. After moving Xcode.app to the Trash and emptying it, one can manually delete the aforementioned directories via the Finder (with the `Go > Go to Folder` menu) or using terminal commands like `rm -rf ~/Library/Developer`. It is critical to note that deleting contents of `/Library/Developer` (the system-wide library, not the user's) is not recommended, as it may contain command-line tools installed separately. Furthermore, one should consider the implications for related tools; uninstalling Xcode does not automatically remove the command-line developer tools, which are a separate package invoked by running `xcode-select --install`. These can be removed, if desired, by deleting the `/Library/Developer/CommandLineTools` directory.

The primary implication of this process is that it allows for a clean slate, which is especially valuable when preparing for a major Xcode version upgrade or diagnosing build system issues. Unlike system-level software, Xcode's design minimizes its footprint outside its bundle, making its removal straightforward. For most users, simply deleting the app is sufficient. The additional steps of purging user caches and developer data are remedial actions targeted at specific problems, not a routine requirement. This distinction is important because unnecessarily deleting the `~/Library/Developer` folder will also erase all custom simulator images, project archives, and device symbols, forcing them to be re-downloaded upon reinstalling Xcode, which is a time-consuming process. Therefore, the cleanest uninstall is context-dependent, balancing the need to eliminate corruption against the cost of re-downloading necessary components.