2

I currently have Xcode (along with command line tools) and gfrotran from HPC installed on my Yosemite system, and would like to replace HPC's gfortran with Homebrew's (because I'm having trouble building Python packages with the HPC gfortran).

What are the steps to accomplish this?

I want to be sure that

  1. HPC's gfortran is gone (I just want one Fortran) and
  2. Apple's tools still work (for Xcode, Swift, OS X and iOS development, etc.)

and of course

  1. that I have a working version of gfortran that reliably builds Python packages.

Can this be done? I see for example that Homebrew's gfortran is now packaged as part of gcc, so it looks like I'll end up with two versions gcc (which I'd like to avoid) or one that doesn't play well with Xcode.

What are the steps to accomplish 1-3?

orome
  • 45,163
  • 57
  • 202
  • 418
  • Can't advise re 1 but Homebrew's `gcc` package installs binaries with suffixed names like `gcc-4.9`, *except* for gfortran, which is installed without a suffix. Homebrew gcc's libraries are sandboxed in a way that should not interfere with the hpc binaries. `mv /usr/local/bin/gfortran /usr/local/bin/gfortran-hpc` should be sufficient to allow `brew install gcc` to succeed and work correctly. The presence of the HPC and Homebrew gcc's should not affect Apple's tooling. Apple does not ship gcc in recent Xcodes; /usr/bin/gcc is a stub that invokes clang. – Tim Smith Jan 12 '15 at 17:44
  • 1
    Time Machine is your friend... ensure you are running proper backups before you start. – Mark Setchell Jan 12 '15 at 17:46
  • @TimSmith: Is there some forcing or overwriting option I should use (or some other way) to deal with all the files HPC's gfortran installed (issue 1)? – orome Jan 12 '15 at 23:32
  • Are they causing trouble? If you want to get rid of the HPC files, downloading the tarball you installed from and doing something like: `cd /; tar tzf path/to/gfortran.tar.gz | sort -r | while read file; do if [ -d "$file" ]; then rmdir "$file"; else rm -f "$file"; fi; done` should remove all the files they install. Try this using echo instead of rm first to make sure you're happy with what it's about to do. It will try and rmdir some directories like `/usr`, which will be harmless, since rmdir won't rm dirs that aren't empty. – Tim Smith Jan 12 '15 at 23:48
  • @TimSmith: I get complaints or trip-ups now and then — I'd feel better without junk hanging around that I don't use (esp. if Homebrew takes steps to avoid them when there there, that it wouldn't if they weren't). – orome Jan 12 '15 at 23:52
  • You could consider removing all of `/usr/local/`, at the guess that HPC Fortran installed all its files below that subdirectory; that won't affect your system. After that, reinstall Homebrew and all the necessary packages. Perhaps replace "removing all of" with "making a copy of" to e.g. `/usr/local-bck/`; the latter won't be on your path, and can safely be deleted once it turns out everything works again. –  Jan 13 '15 at 00:09
  • As for point 3: I think that just relies on your `PATH` and `LD_LIBRARY_PATH` to include `/usr/local/bin` & `/usr/local/lib`, so that Python packages like scipy can compile against fortran. –  Jan 13 '15 at 00:10
  • @Evert I believe the HPC files will be in `/usr/bin` the `/usr/local/bin` directory will have all of the executables linked by homebrew – Ajay Jan 13 '15 at 18:19
  • 1
    @Ajay From the [HPC pages](http://hpc.sourceforge.net/): "Then gunzip gcc-4.9-bin.tar.gz (if your browser didn't do so already) and then sudo tar -xvf gcc-4.9-bin.tar -C /. It installs everything in /usr/local.". It's not only Homebrew that installs there; `/usr/local` is pretty much a default for any additional (unix-like) software. –  Jan 14 '15 at 08:25

1 Answers1

1

I recently worked through this very same problem. This is how I got/have it working on my Yosemite system.

Some things about home-brew and the command line tools compilers:

  1. The compiler you get through home-brew will overwrite the existing one if it is in the same place. If you have a fortran compiler that you obtained from the command line tools then it will not be affected.(Home-brew will warn you about this before doing anything)

  2. The binaries for the compilers you get through the command line tools are in /usr/bin .

  3. The compilers (and anything else) you obtain using home-brew are stored in the cellar ( /usr/local/Cellar) and the executables are linked into the directory /usr/local/bin.

What to do?

  1. Modify the path: I only needed to use the compilers I got through home-brew so I moved /usr/local/bin to the top of my $path this ensures that the /usr/local/bin directory is searched before /usr/bin.

  2. Use aliases : You can create an alias for each compiler so that you can use them interchangeably as you wish. To create an alias you will have to modify your shell-rc file. On my system I use the tcsh, and to create an alias for the home-brew compiler I would add something similar to this to my ~/.cshrc file.

    alias brewgfortran '/usr/local/bin/gfortran'
    

    this now executes the home-brew gfortran-4.9 executable that is stored in my cellar and linked to /usr/local/bin/gfortran/

  3. IF you absolutely want rid of the apple compilers you can of course remove them from the /usr/bin/ directory completely. I don't think this is the best idea though. I have shown you a few ways to avoid using them and if you ever needed them for some reason you would be SOL. I cant say if those tools you need will work without them as I have never used any of those, however I know it will build python packages for you (sorry hope this still helps)

NOTE: If you are not using the same shell as me the syntax for the alias is a little different (I think) just google it or man alias

Ajay
  • 407
  • 4
  • 14
  • FWIW, I ended up manually removing the files that HPC's gfortran installed (followed by a `brew install` of gfortran and some prunes and overwriting of links as suggested by the install). Except for [`texlive`](http://stackoverflow.com/q/27946302/656912) and `mysql-utilities`, `/usr/local` now seems to be comfortably under Homebrew's control. Apple's `gcc` seems undisturbed. – orome Jan 14 '15 at 15:32
  • glad to hear it, backups really are your friend in cases like this if it breaks you always want to be able to go back! – Ajay Jan 14 '15 at 18:23