Can I install Xcode on an external hard drive along with the iPhone Simulator.app?

SwiftXcodeMacosFlutterMobile Development

Swift Problem Overview


I want to install xcode to deploy a cross platform flutter application but I cant find enough space for Xcode is there any alternative solutions to just installing it on the internal storage

Swift Solutions


Solution 1 - Swift


PLEASE READ THIS FIRST!
Currently, this answer is only valid for systems that runs:

XCode <= v.11.3 running macOS <= v.10.15.2

Why? (Short Version):

With XCode 11.3.x, Apple activated a few (until now) dormant checks in /usr/lib/libxcselect.dylib that enabled checking if the developer tools is located on a read-only / immutable system partition guarded by SIP and gets triggered when you do a xcode-select -s directory switch attempt.

The 11.x "Big Sur" macOS versions, locked it down much harder still, because of things like this. Moving system related files, or even booting from external drives won't work, because the new "encryption seal", part of the new SSV (Signed System Volume) refuses to boot or run select programs if the hash is altered (files in / out etc).

I have not yet found a way to work around these checks. I take no responsibility for broken systems after using this method, and if you choose to tinker with a newer version of XCode / macOS, please take a full backup first! Good Luck!


Installing Xcode, Simulators and Other Tools to External Storage

As mentioned in the comments, if you already have Xcode installed the process is quite simple. Start by copying Xcode from the Internal HD to an External drive, rename the original and run the commands from step 4 & 5, and this should do the trick. If so, delete the original (now renamed) directory / app bundle.

My experience is that if you don't have Xcode already, the process is a bit more involved.

There may be simpler ways to do this, but after getting different errors for every thing I've tried, I've done it this way on a MacBook Pro 16" running macOS Catalina (10.15.2) and Xcode 11.3:

I have my external drive attached to the MacBook at all times, using a bit of Velcro as the Samsung T5 drive I use is so small and light. It's mounted at:
/Volumes/SSD

On the external drive I've copied Xcode into:
/Volumes/SSD/Applications

Follow this procedure for installing Xcode:

  1. Download the latest 11.3 Xcode release (not the Beta) from Apple's Developer Site (This is a 7.3GB Download and you need to register for a free developer account by the way)

  2. Install the Xcode command-line tools (to the internal drive), which can be triggered by running the following command in a terminal: sudo xcode-select --install
    This will trigger the installation of the command-line tools and establish the /Library/Developer/CommandLineTools path and set this as the default developer tools path after installation.

  3. Now, the Xcode download comes as a .xip file that needs to be expanded / unpacked using the Archive Utility included with macOS.
    I've already created a directory on the SSD:
    /Volumes/SSD/Applications
    and moved the Xcode_11_3.xip file here before extracting it by double- clicking it in the Finder.
    NOTE: It will unpack to the same folder as the .xip file, into Xcode.app but leaves the 7.3GB .xip file there as well. After unpacking, you may move the .xip file somewhere for backup or just delete it.

  4. Now change the default developer tools directory with command:
    sudo xcode-select -s /Volumes/SSD/Applications/Xcode.app/Contents/Developer
    then do another zsh -lor restart the Terminal.app.

  5. After setting the Xcode.app as the default developer tools directory, run this command, to have Xcode figure itself out:
    /usr/bin/xcrun --find xcodebuild

    This took a little while, then I got back:
    /Volumes/SSD/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild

Moving The Simulators / Emulators

The simulators, caches and all that also takes up a considerable amount of space but lives elsewhere.
For Xcode, the simulators are normally located within:
~/Library/Developer/CoreSimulator

You'll want to move this whole directory structure to your external drive if you're looking to maximize the available space on the local drive. You can use a regular move operation via Finder.app by first doing a regular ⌘ + C (cmd+c) to copy ~/Library/Developer/CoreSimulator then in the target location, You can use ⌥ + ⌘ + V (opt+cmd+v) to move the copied contents directly (might require admin password).

I use /Volumes/SSD/Library/Developer/

Just had to mention this as many don't know how to properly "cut and paste" files in the Finder, ending up copying first then going back to delete... :)

Now make a symlink using:

ln -s /Volumes/SSD/Library/Developer/CoreSimulator /Users/<your_user>/Library/Developer

You should now be able to use and update the simulators as usual. First time run may throw an error, but subsequent runs should be fine. Sometimes a reboot might be a good thing as well...

The Android emulators are by default located somewhere beneath ~/.android/
Use the same procedure as for the Xcode simulators to move the whole ~/.android directory to a place on your external drive and symlink as described, so you end up with something like:

.android -> /Volumes/SSD/Library/android

when you do a $ ls -la ~ in your Terminal.

Note For Homebrew Users

If you're using Homebrew for installing packages (like many does), it seems as if Homebrew won't register that you have the CommandLineTools installed if you move the /Library/Developer/CommandLineTools directory, and will try to compile some bottles from source.
Homebrew apparently needs some tools found in the separate Command Line Tools package installed with sudo xcode-select --install that's missing from the regular Xcode install (I noticed this when upgrading to a new version of Python, it was still being compiled from source no matter what I tried.)
So, if you use Homebrew, you're probably better off keeping the Command Line Tools installed at the default location. Just install as described with the sudo xcode-select --install command and leave it there, it's not taking up much space anyway.

IMPORTANT, remember to accept the xcodebuild licenses before using a tool that depends on it, using a command like this (with your own path):

sudo /Volumes/SSD/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -license accept

or in cases where the developer tools are already detected and found on an external drive, and the path has been set by XCode:

sudo xcodebuild -license accept should do the trick.

As I said, there might be simpler solutions out there, but after doing it this way I've been able to use Homebrew without errors and Xcode + tools with MacOS, iOS and Flutter frameworks.

Also, I've created an alias to the Xcode.app in /Applications to have it conveniently placed together with the other apps. (Cmd + Opt drag the Xcode.app to /Applications in Finder). Saved myself a ton of space on the internal drive this way.


In response to questions in the comments:

> Can I upgrade Xcode / Simulators after using this method?

As long as you create a good old "alias" from the external drive's Xcode.app to /Applications/Xcode.app by dragging the app while holding ⌥ + ⌘, I've not had any problems updating, BUT I upgrade by downloading from the Apple Developer Site, not through macOS AppStore, as I've noticed that the AppStore doesn't accept the alias and thinks that Xcode isn't installed.


Updates regarding Xcode Versions > 11.3

As I mentioned in the top of the answer, I can't vouch for this answer if you're using an Xcode version higher than 11.3.

I've gone through all the steps using a fresh install on a new machine.

I experienced a couple of showstoppers while trying to figure this one out, and I only had limited time to spare for doing this. The problems were a bit more involved than expected.

TODO:
✅ Disk arrived today (Tue, Sep 8)
✅ Install macOS, Xcode, Android SDK and Flutter SDK dev files
✅ Move Flutter SDK, Android SDK and Android emulator to external SSD
✅ Move iOS Simulator files to external SSD
[] FAILED: Move Xcode and Platform files to external SSD
✅ Adapt Zsh environment variables / scripts to reflect the changes


It appears that those who have SIP enabled (probably most users) will get in trouble when accessing tools from within the Xcode app bundle if it's moved outside the internal drive.

You may think that, "hey, I have my tools in /usr/bin or somewhere else, but the problem is that these files are merely shim binaries, which use a system library to resolve a path to a Developer directory, where all the actual executable files, libraries and support files are installed.

This complicates matters further as you now no longer even know which of these files are in actual use. Just try doing:

$ otool -L /usr/bin/xcrun
# or
$ otool -L /usr/bin/xcode-select

And see what pours out... Same goes for most of the tools.

If you disassemble /usr/lib/libxcselect.dylib (is that allowed? ) there's apparently some additional checks being performed when running Xcode after version 11.3.

I went back and checked and the configuration have had these tests available for a few versions, but they haven't been activated in previous consumer builds.

So when a directory switch is attempted as described in my original answer, the libxcselect tool will now perform at least one (in)sanity check to ensure that Xcode and its tools are run from internal (safe) storage, which has an immutable system configuration guarded by SIP. System Integrity Protection, so, you can't just move or delete it.

My guess is that you'll have to disable SIP to be able to make this work, and that is not an acceptable solution, as it opens up for lots of security and stability issues (even worse performance).

Finding a Middle Ground

Problem: How to free up space on an internal drive, by moving developer files to an external drive.
I've tried pretty much everything I can think of regarding the moving Xcode part, but I've met new roadblocks and showstoppers no matter what.

SO. I had to throw in the towel on this one, finding a compromise. I can live with having saved approximately 50GB of space on my MacBook Pro's internal 256GB NVMe drive.

I had no trouble moving: ~/Library/Android/* (The whole Android SDK directory) ~/.android/* (Caches and .avd emulator image files)

Using nothing but symbolic links, after copying the contents and deleting the originals. This is only interesting for those who develop using the Android SDK and tools, so sadly I wasn't able to solve this madness caused by Apple's restrictive new policy regarding executable files in "foreign, hostile" locations.
These two directories alone saved me a fair share of space, so I guess for the time being that's about it.

I've tried moving some parts of the Xcode bundle out of the app bundle with varying degree of success, but as you can see in this screenshot:

Xcode Space Usage

The bulk of the Xcode.app is within the "Platforms" directory, and when I start messing with those files, the build tools blows up on me, but sometimes not, so I really don't know.

The Simulator files themselves are possible to move, and this will save you anything between a few gigabytes to plenty of GBs depending on how many platforms (iOS / iPadOS etc.) versions you use.

These are located inside: ~/Library/Developer/CoreSimulator I've been able to move this whole CoreSimulator directory without too much trouble using symlinks as explained in the original answer.

I will continue trying to figure this one out, but right now, this is where it's at.


Solution 2 - Swift

I just installed Xcode 12.3 to /Applications then copied the .app to my external drive, then deleted the original. After that:

ln -s /Volumes/ExternalSSD/Applications/Xcode.app /Applications/Xcode.app

It took a while to launch for the first time, but subsequently it's now fine. MacOS 11.1, M1 2020 Air.

(No need to clone the OS or boot off your external drive, like the other posts suggest).

Solution 3 - Swift

I found out a simpler solution. Create a new user on your Mac. Give administrator privileges(optional), set the home directory of the user account you just created to be an external hard drive. Then login to the new user and install Xcode at ~/Applications directory not /Applications. Then Xcode is installed on your external ssd. No problems using it so far for me! Hope it helps.

Edit: I forgot to mention I should download Xcode from developers website. Haven’t tried downloading from App Store.

Solution 4 - Swift

As an alternative to just moving XCode to an external drive you could also clone your mac disc and move the whole operating system onto your external drive and make it bootable.

Things you need:

Install the cloning software, follow the instructions and you'll have a bootable external drive in less than an hour (depending on what you are cloning)

You now have a portable development disk which can be plugged in and booted from the same mac. Booting from other macs may not work as cseder suggest in the comments.

On first boot and usage of XCode, the Apple OS will perform some verification of apps, but once that is done you should be fine.

I have a 2018 mac-mini running Big Sur with only 128GB internal SSD. Every time I needed to upgrade XCode I had to delete all the simulators. Upgrading to Big Sur was even harder :-/

Performance?

The external drive (Samsung T5) is 3x quicker to write to than the cheap internal SSD that Apple use on the mac-mini. Read speeds are about the same according to BlackMagic. Overall, Flutter app builds on the external drive are about 10% quicker.

Solution 5 - Swift

@cseder you're a life saver!

Btw, If you are getting issues or takes a long long time in Mac Catalina to verify while doing step 5 /usr/bin/xcrun --find xcodebuild just:

  1. Turn off the computer
  2. Turn on, and quick enter in Secure mode (Press CMD + R multiple times)
  3. Login to your account and open the terminal once Secure mode is on
  4. Run this command csrutil disable <- will disable the verification of software download from the internet
  5. Run sudo reboot

And then you can open Xcode directly without doing any /usr/bin/xcrun --find xcodebuild

Note after you are able to run Xcode then make sure to Turn Off again and enable csrutil enable in secure mode.

Solution 6 - Swift

I've found a really simple way to install Xcode in an external drive, but the simulator files are still downloaded into the Mac installation.

  • Get the standalone Xcode application from: Apple Developer Xcode Downloads (Sign in using an Apple Developer Account)

  • After login, type in the version that you'd like, and download the Xcode_x_x_x.xip file. Keep in mind that Xcode 11.4.1 is 8 gigabytes, so this will take awhile depending on your internet connection.

  • Once the file is downloaded, click on .xip to extract it. Your Mac will extract it to the same folder you downloaded it to. This extraction process is automatic. You don't need to do anything more after you click on the .xip file. This step will take a few minutes.

  • [Optional] Once extracted, rename the application to “Xcode11.x.x” if you are using multiple versions.

  • Drag that file to your external drive.

  • Maybe you will find a not found error when submitting your app to the Mac App Store with Transporter. In that case go to Preferences > Locations > Command Line Tools, and select your version.

  • This is how I'm working now for a Mac application with Unity. Later I'll try to do the same with iOS. I'll update here if I found another problem and a way to fix it (or I'll look for help here if I can't).

Solution 7 - Swift

Here is what worked for me, not only for XCode, but for all of the apps.

  1. Install MacOS into the external media (SSD would be better).
  2. You need to enable booting from an external drive. You do that by Pressing Command and R right after you see the apple sign after reboot
  3. Once you have MacOS installed on the external media, install any application you want. WhatsApp, XCode, IntelliJ, Adobe Photoshop ...etc
  4. Once you are done, change the boot settings, to boot from the MacMini or Macbook pro drive.
  5. Create symbolic links to the apps you installed on your external drive

Example:

cd /Applications ln -s "/Volumes/Extreme SSD/Applications/XCode.app" XCode.app

I have tried this on all applications on my Mac and it worked like a charm.

Advantages: - Less Headache. Copying XCode directory into external SSD might not work. I have done this, and weirdly enough, there was a directory loop and I ended up losing all my external SSD space.

- The application is installed in the way it should

Disadvantages: - You have to lose 12GB of for the installation of Mac

This is so far working for me like a charm.

Solution 8 - Swift

Spent a long time with @cesder answer, which is definitely great. I did found an issue with moving the simulators. Xcode > 11.3 wouldn't find them if I used a simlink, but using an alias worked perfectly. To create an alias: Right click on the CoreSimulator folder on your external drive, and select Make alias, then just copy it on ~/Library/Developer/


Edit: I've been able to successfully run Xcode from my external drive by formatting it to 'Mac OS extended (journaled)'. It was as ExFAT, which Xcode didn't like for some reason. enter image description here

I haven't tested moving the simulators to the external drive yet, but moving all Xcode is more than enough for me. To move Xcode to your external drive, just follow @cesder instructions for Xcode <= 11.3 and it should work. I've tested it on 12.2 (12B45b).

Solution 9 - Swift

> Caution : Only tried for cordova projects. Thanks @cseder

Reporting from macOS Big Sur(11.0.1),Xcode 12.3, MacBook Air (2017), WD external HDD (not SSD) :

  1. Download the .xip file from apple developer website
  2. Move the .xip file to external hard drive (I am also using this hard drive as Time Machine. I am not sure this situation is a factor)
  3. Be sure that your local hard drive has about minimum 25 GB free space. Because while installing process local hard drive filling, after finishing installation, the free space return.
  4. Double click the .xip file.
  5. Be patient. Wait a long time:) (I did not experienced with SSD:)
  6. And voila!

Note:

  1. Your Xcode app will not shown in launchpad.
  2. I did not use fully functional. Only used for compile a cordova project.

Solution 10 - Swift

System MacBook Pro, with external SSD., with MacOS BigSur Version 11.2.1 I Install the Xcode Version 12.4 on the local disk. After the installation i copied Xcode.app to the external disk, and delete the version on the local disk. No further changes made. Start the Xcode from the external Disk. without problem. TAKE CARE: First start takes over 5 Minutest

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOmar EmamView Question on Stackoverflow
Solution 1 - SwiftC. SederqvistView Answer on Stackoverflow
Solution 2 - SwiftBSUKView Answer on Stackoverflow
Solution 3 - SwiftGeorge VlassisView Answer on Stackoverflow
Solution 4 - SwiftSoftWyerView Answer on Stackoverflow
Solution 5 - SwiftJuan RicardoView Answer on Stackoverflow
Solution 6 - SwiftramzView Answer on Stackoverflow
Solution 7 - SwiftKhaledinhoView Answer on Stackoverflow
Solution 8 - SwiftahgView Answer on Stackoverflow
Solution 9 - Swifthakan akgülView Answer on Stackoverflow
Solution 10 - SwiftMarcelView Answer on Stackoverflow