我可以将Xcode与iPhone Simulator.app一起安装在外部硬盘驱动器上吗? [英] Can I install Xcode on an external hard drive along with the iPhone Simulator.app?

查看:401
本文介绍了我可以将Xcode与iPhone Simulator.app一起安装在外部硬盘驱动器上吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想安装xcode来部署跨平台的flutter应用程序,但是我找不到足够的空间来存放Xcode,是否有其他解决方案可以将其安装在内部存储中

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

推荐答案

将Xcode和好友安装到外部驱动器

如评论中所述,如果您已经安装了Xcode,则过程非常简单. 首先将Xcode从内部HD移至外部HD,然后运行第4步和第2步中的命令. 5,这应该可以解决问题.

Installing Xcode and friends to an external drive

As mentioned in the comments, if you already have Xcode installed the process is quite simple. Start by moving Xcode from the Internal HD to an External one and run the commands from step 4 & 5, and this should do the trick.

我的经验是,如果您尚未安装Xcode,则过程会有些复杂.

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

执行此操作的方法可能更简单,但是在尝试过的每件事上都遇到不同的错误后,我在运行MacBook Pro 16的MacBook Pro上执行了此操作 macOS Catalina(10.15.2) Xcode 11.3 :

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:

我始终将外部驱动器连接到MacBook,使用一点魔术贴,因为我使用的Samsung T5驱动器又小又轻. 它安装在:

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

在外部驱动器上,我将Xcode安装到:

On the external drive I installed Xcode into:

/Volumes/SSD/Applications

按照以下过程安装Xcode:

following this procedure for installing Xcode:

  1. Apple的开发人员网站(这是一个7.3GB下载,您需要注册一个免费的开发者帐户)

  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)

安装Xcode命令行工具(到内部驱动器),可以通过在终端中运行以下命令来触发:

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

这将触发命令行工具的安装并建立
/Library/Developer/CommandLineTools

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.

现在,Xcode下载是一个.xip文件,需要使用 macOS随附的存档实用程序.
我已经在SSD上创建了一个目录:
/Volumes/SSD/Applications
并将Xcode_11_3.xip文件移动到此处,然后通过在Finder中双击将其解压缩.
注意: 它将与.xip文件解压缩到Xcode.app的同一文件夹中,但同时保留7.3GB的.xip文件.解压缩后,您可以将.xip文件移动到某个位置以进行备份,也可以将其删除.

Now, the Xcode download comes as a .xip file that needs to be expanded / unpacked using the Archive Utility included with macOS.
I've 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.

现在使用以下命令更改默认的开发人员工具目录:
sudo xcode-select -s /Volumes/SSD/Applications/Xcode.app/Contents/Developer
然后再执行一次zsh -l或重新启动Terminal.app.

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.

将Xcode.app设置为默认的开发人员工具目录后,运行以下命令以使Xcode本身显示出来:
/usr/bin/xcrun --find xcodebuild

这花了一段时间,然后我回来了:
/Volumes/SSD/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild

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

模拟器/仿真器

模拟器,缓存等也占用相当多的空间,但仍位于其他地方.
对于Xcode,模拟器通常位于~/Library/Developer

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 beneath ~/Library/Developer

如果要最大化本地驱动器上的可用空间,则需要将整个目录结构移至外部驱动器. 您可以通过Finder.app使用常规移动操作,方法是先进行常规⌘+ C(cmd + c)复制~/Library/Developer,然后在目标位置进行复制,例如 /Volumes/<ext_drive_name>/<some_dir_name>,我使用/Volumes/SSD/Library/,您可以使用⌥ + ⌘ + V(opt + cmd + v)直接移动复制的内容(可能需要管理员密码).

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 then in a target location, like /Volumes/<ext_drive_name>/<some_dir_name>, I use /Volumes/SSD/Library/ you can use ⌥ + ⌘ + V (opt+cmd+v) to move the copied contents directly (might require admin password).

只需提及这一点,因为许多人不知道如何在Finder中剪切和粘贴"文件,最终先进行复制,然后再删除...:)

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

现在使用ln -s /Volumes/SSD/Library/Developer /Users/<your_user>/Library/建立符号链接,您应该能够照常使用和更新模拟器.

Now make a symlink using ln -s /Volumes/SSD/Library/Developer /Users/<your_user>/Library/ and you should be able to use and update the simulators as usual.

默认情况下,Android模拟器位于~/.android/...下的某个位置 使用与Xcode模拟器相同的过程,按照说明将整个~/.android目录移动到外部驱动器和符号链接上的某个位置,因此最终得到以下结果:

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

在终端中执行$ ls -la ~时.

如果您正在使用 Homebrew 来安装软件包(就像许多安装包一样),则好像Homebrew没有注册如果您移动/Library/Developer/CommandLineTools目录并已尝试从源代码编译某些瓶子,则说明您已安装CommandLineTools.
显然,Homebrew仍然需要一些与sudo xcode-select --install一起安装的单独命令行工具包中的某些工具,这些工具在常规Xcode安装中是缺少的(我在升级到新版本的Python时注意到了这一点,无论我使用什么工具,都仍在从源代码进行编译尝试过的.)

因此,如果使用Homebrew,最好将命令行工具安装在默认位置. 只需按照sudo xcode-select --install命令的说明进行安装,然后将其保留在那里,反正不会占用太多空间.

If you're using Homebrew for installing packages (like many does), it seems as if Homebrew doesn'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 still 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.

我不知道,但是在我看来,这是以某种方式硬编码到Homebrew的配置中的.

I don't know, but it seems to me that this is somehow hard-coded into Homebrew's configuration somewhere or something.

此外,在使用依赖于它的工具之前,请记住接受xcodebuild许可证,并使用类似以下命令(具有自己的路径):

Also, 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


如我所说,可能会有更简单的解决方案,但是 这样操作后,我就可以在MacOS,iOS和Flutter框架中无错误地使用Homebrew和Xcode +工具.


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.

此外,我在/Applications中为Xcode.app创建了一个别名,以方便将其与其他应用程序放在一起. (将Cmd + Opt拖动Xcode.app到Finder中的/Applications中). 这样就为自己节省了内部驱动器上的大量空间.

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.

针对评论中的问题:

使用此方法后是否可以升级Xcode/模拟器?

Can I upgrade Xcode / Simulators after using this method?

只要您按住⌥ + ⌘并拖动应用程序即可从外部驱动器的Xcode.app到/Applications/Xcode.app创建良好的旧别名",则 BUT 不会出现任何问题如我所注意到的,我通过从 Apple Developer Site 下载,而不是通过macOS AppStore下载,从而进行了升级AppStore不接受别名,并认为未安装Xcode.

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.

这篇关于我可以将Xcode与iPhone Simulator.app一起安装在外部硬盘驱动器上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆