macos 如何将 osx 中的 GCC 从 xcode 移动到 /usr/bin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3972382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:17:35  来源:igfitidea点击:

How to move GCC in osx from xcode to /usr/bin

macosgccterminal

提问by kjones1876

I have the gcc compiler in "/Developer/usr/bin/gcc" but when i type in gcc into terminal it says can not be found, i assume this is because its not in the "/usr/bin" dir. So can i a) move gcc from the first dir to the second, or set some kind of shortcut pointing gcc to "/Developer/usr/bin/gcc"

我在“/Developer/usr/bin/gcc”中有 gcc 编译器,但是当我在终端中输入 gcc 时,它说找不到,我认为这是因为它不在“/usr/bin”目录中。所以可以 ia) 将 gcc 从第一个目录移动到第二个目录,或者设置某种快捷方式将 gcc 指向“/Developer/usr/bin/gcc”

回答by esco_

The tip thewoolleyman linked to worked for me! I have installed Xcode 4.3.3 via the App Store. I did not have to install Xcode "again", seems Apple solved that. What I had to do are the following easy steps:

thewoolleyman 链接的小费对我来说有效!我已经通过 App Store 安装了 Xcode 4.3.3。我不必“再次”安装 Xcode,似乎 Apple 解决了这个问题。我必须做的是以下简单步骤:

  1. Open Xcode
  2. Go To Preferences > Downloads
  3. Install the Command Line Tools
  1. 打开 Xcode
  2. 转到首选项 > 下载
  3. 安装命令行工具

Thanks to Guy and his post https://stackoverflow.com/a/9377095/1451903

感谢盖伊和他的帖子https://stackoverflow.com/a/9377095/1451903

回答by Tarka

Two choices:

两种选择:

  1. Edit your ~/.bashrcor ~/.bash_profile(or equivalent system files) and add /Developer/usr/bin/gccto $PATH: export PATH="$PATH:/Developer/usr/bin/"
  2. Create a link (symlink in this example) in your /usr/bindirectory pointing to the real file: ln -s /Developer/usr/bin/gcc /usr/bin/gcc
  1. 编辑您的~/.bashrc~/.bash_profile(或等效的系统文件)并添加/Developer/usr/bin/gcc$PATHexport PATH="$PATH:/Developer/usr/bin/"
  2. 在您的/usr/bin目录中创建一个指向真实文件的链接(在本例中为符号链接):ln -s /Developer/usr/bin/gcc /usr/bin/gcc

Note: in XCode 4.5 on MacOS 10.8 the path is now:/Applications/Xcode.app/Contents/Developer/usr/bin

注意:在 MacOS 10.8 上的 XCode 4.5 中,路径现在是:/Applications/Xcode.app/Contents/Developer/usr/bin

回答by Ignacio Vazquez-Abrams

Use ln -sto create a symlink in /usr/bin, or add /Developer/usr/binto $PATH.

用于ln -s在 中创建符号链接/usr/bin,或添加/Developer/usr/bin$PATH.

回答by Potatoswatter

You can, in theory, hardlink it to the proper place.

理论上,您可以将其硬链接到适当的位置。

The official way to do this is to install the optional "command-line tools" with the XCode installer. This wastes several hundred megabytes as it installs a new copy of the same compiler.

执行此操作的官方方法是使用 XCode 安装程序安装可选的“命令行工具”。这会浪费数百兆字节,因为它安装了相同编译器的新副本。

I wrote a shell script once to compare the installation trees of the "XCode" installation and the "command-line" installation and hardlink together all the files that were identical. It worked perfectly but the next upgrade undid it.

我曾经写过一个 shell 脚本来比较“XCode”安装和“命令行”安装的安装树,并将所有相同的文件硬链接在一起。它运行良好,但下一次升级取消了它。

Another alternative is to download the GCC source from their CVS (not much bigger than downloading the massive XCode installer), and build it into usr/bin/yourself. Then you have the latest and greatest (or your choice of many newer and better versions) to play with.

另一种选择是从他们的 CVS 下载 GCC 源代码(比下载大量的 XCode 安装程序大不了多少),然后将其构建到usr/bin/自己中。然后您就可以使用最新最好的(或您选择的许多更新更好的版本)。

回答by thewoolleyman

If you have "installed" Xcode from the App Store, check out this thread:

如果您已从 App Store“安装”Xcode,请查看此主题:

Mac OS X Lion Xcode problems using RVM

使用 RVM 的 Mac OS X Lion Xcode 问题

Apparently, "installing" Xcode from the app store doesn't actually install it, you must manually run the installer (search for "Install Xcode" in spotlight).

显然,从应用商店“安装”Xcode 并没有真正安装它,您必须手动运行安装程序(在聚光灯下搜索“安装 Xcode”)。