Brew Gcc



Installs (30 days) gcc: 92,508: gcc -HEAD: 182: gcc -without-multilib: 1: Installs on Request (30 days) gcc: 42,761: gcc -HEAD: 182: Build Errors (30 days) gcc: 219. Currently, I'm using a 2016 13' MBP TB at university on the programming lessons where we use the brew's edition of gcc (Homebrew GCC 10.2.0), not the clang. I'm planning to surprise myself with an M1 MBA or MBP but I'm not sure if homebrew's gcc compiler is compatible with the new Macs.

The Homebrew package manager may be used on Linux and Windows Subsystem for Linux (WSL). Homebrew was formerly referred to as Linuxbrew when running on Linux or WSL. It can be installed in your home directory, in which case it does not use sudo. Homebrew does not use any libraries provided by your host system, except glibc and gcc if they are new enough. Homebrew can install its own current versions of glibc and gcc for older distributions of Linux.

Features, installation instructions and requirements are described below. Terminology (e.g. the difference between a Cellar, Tap, Cask and so forth) is explained in the documentation.

Features

  • Can install software to your home directory and so does not require sudo
  • Install software not packaged by your host distribution
  • Install up-to-date versions of software when your host distribution is old
  • Use the same package manager to manage your macOS, Linux, and Windows systems

Install

Instructions for a supported install of Homebrew on Linux are on the homepage.

The installation script installs Homebrew to /home/linuxbrew/.linuxbrew using sudo if possible and in your home directory at ~/.linuxbrew otherwise. Homebrew does not use sudo after installation. Using /home/linuxbrew/.linuxbrew allows the use of more binary packages (bottles) than installing in your personal home directory.

The prefix /home/linuxbrew/.linuxbrew was chosen so that users without admin access can ask an admin to create a linuxbrew role account and still benefit from precompiled binaries. If you do not yourself have admin privileges, consider asking your admin staff to create a linuxbrew role account for you with home directory /home/linuxbrew.

Follow the Next steps instructions to add Homebrew to your PATH and to your bash shell profile script, either ~/.profile on Debian/Ubuntu or ~/.bash_profile on CentOS/Fedora/Red Hat.

You’re done! Try installing a package:

Gcc

If you’re using an older distribution of Linux, installing your first package will also install a recent version of glibc and gcc. Use brew doctor to troubleshoot common issues.

Requirements

  • GCC 4.7.0 or newer
  • Linux 2.6.32 or newer
  • Glibc 2.13 or newer
  • 64-bit x86_64 CPU

Paste at a terminal prompt:

Debian or Ubuntu

Fedora, CentOS, or Red Hat

ARM

Homebrew can run on 32-bit ARM (Raspberry Pi and others) and 64-bit ARM (AArch64), but no binary packages (bottles) are available. Support for ARM is on a best-effort basis. Pull requests are welcome to improve the experience on ARM platforms.

You may need to install your own Ruby using your system package manager, a PPA, or rbenv/ruby-build as we no longer distribute a Homebrew Portable Ruby for ARM.

32-bit x86

Homebrew does not currently support 32-bit x86 platforms. It would be possible for Homebrew to work on 32-bit x86 platforms with some effort. An interested and dedicated person could maintain a fork of Homebrew to develop support for 32-bit x86.

Alternative Installation

Extract or git clone Homebrew wherever you want. Use /home/linuxbrew/.linuxbrew if possible (to enable the use of binary packages).

Homebrew on Linux Community

Installing Amber/AmberTools on macOS has become much easier though is not to be considered completely trivial. Below different methods are presented to install the current version of AmberTools, where the method should be the same for Amber.

After the latest update of Xcode to 10.2.1, problems started emerging when trying to use a compiler other than clang. It is now once again possible to use gcc as long as you are using the latest and patched version of whichever gcc version you choose.

This will require you to install some things and run some commands through the built in “command interpreter” which on macOS is called Terminal(.app). You find this app in your Applications folder, in a sub folder called Utilities or by using Spotlight, the litle magnifying glass in the top right corner of the screen (alternatively through the keyboard shortcut cmd+space on your keyboard, assuming this is active) and search for “Terminal”. When you are expected to run commands in the terminal, they will be presented in this manner:

Some commands might require you to “side-scroll” to see the entire sequence as they might continue “off screen”. With this explained I think it is time to get started. I will now explain how to compile AmberTools19(/Amber18) with the package manager “Homebrew” and the Apple version of the C compiler package clang. Earlier I have offered instructions for using “MacPorts” och binary distributed versions of HPC gcc/gfortran. However, not having enough time and a more acute lack of a stable and available virtual machine with macOS for testing I have had to limit myself somewhat. The process should still be the same regardless of the source one chooses for gcc/gfortran. Remember, only chose one source of installing compilers from as you may accidentally cause conflicts of installing more than one package manager or from more than one source of binaries at once.

If you run into issues I refer you to the AMBER mailing list for help rather than trying to comment here as I am not updating this page regularly enough to be able to help in any reasonable amount of time.

Installing Xcode and accompanying Command Line Tools

Regardless of which package manager or gcc source you select, you need to install Xcode. For this “how-to”, Xcode 10.2.1 was used and you should install this software using the AppStore on your Mac. Command Line Tools (CLT) is needed to run commands and compile using the terminal and is installed after Xcode has been installed by executing the following command in the Terminal(.app).

The step below might no longer be necessary with the latest updates of the amber code though I’ll leave it here since I have installed these headers on my machine already and have yet had time to investigate if this makes a difference. Hence, you might need to install some missing header files by running the following command, opening a PKG installer which is shipped with Xcode10. Follow the on-screen instructions to install.

This step was necessary for AmberTools18 as Apple retired some tools that previously came with Xcode.

Some modules of the Amber package uses X.org X Window System for dealing with GUIs, support for this is no longer the default in macOS in the form of the old X11.app so in order for this to work you need to install XQuartz which has replaced X11.app. I believe you still recieve a popup explaining that you need to install XQuarts when trying to use X11 though you might just as well install the software directly. Visit the developer website at https://www.xquartz.org/ and follow the instructions.

Now you should have installed Xcode and CLT to be able to run commands and compile code with Terminal(.app) and potentially also XQuartz.

Compiling AmberTools19(/Amber18) with macOS clang

You’ve already installed Xcode (right?) so you now have a working C compiler (clang). Now you need a fortran compiler, as this is not shipped with Xcode. You can procure this using any method you chose which works. I use the homebrew package manager. In previous versions of these write-ups I have offered three different ways of obtaining these and installing amber using them and I will leave the outline in this guide as well despite the fact that I have not tested all three alternatives with the latest version of AmberTools. Please note that you should only select one method!

Alternative 1: Homebrew

Homebrew is installed by running a command in the Terminal(.app), please visit the Homebrew website (https://brew.sh/) and confirm the command. This is the only validated method at the time.

Then proceed to install Homebrew GCC 9.1.0 (currently the default version) by running this command:

Since Apple does not supply a version of gfortran, the homebrew version of gfortran will automatically become the default global version by installing gcc. No links, edits or exports are needed.

Alternative 2: MacPorts

Download and install MacPorts and GCC. I have previously evaluated gcc versions 6-8 though not with the latest version of AmberTools. I am unsure if there is a gcc version 9 available from MacPorts as of writing this.

Alternative 3: HPC GCC

Where I have previously chosen HPC gfortran-8.1-bin.tar.gz from http://hpc.sourceforge.net to only install the fortran compiler as I now intend to use Apple clang for the rest. I have not validated that this method currently works with the latest updates of macOS and AmberTools. There is no version 9 available as of writing this.

Everything is installed in /usr/local/. During this process I recieved error messages though the installation worked as intended anyway so I did not dig deeper into this:

Fortran INSTALLLED

You should now have a working installation of gfortran and it is time to move on with the configuration and installation of AmberTools19(/Amber18).

Download AmberTools19(/Amber18) from the developer website (https://ambermd.org/), move the compressed file and then extract the archive in the location where you intend to install AmberTools(/Amber).

Configure and install:

After a decent amount of time you should be greeted with something along the lines of:

You are also presented with a very wise suggestion to add a line of code to you .profile/.bashrc/.cshrc or similar, you should follow this suggestion as it will make you life a lot easier working with amber. For me, using SH/BASH (the macOS default) I execute this command:

You can then elect to “restart” your terminal session by closing the window and opening it again, reading the content of this file again. Alternatively you execute the following command:

After the successful installation of AmberTools(/Amber) you should run through the tests to make sure everything is running smoothly under the hood. You start these test by executing the following:

Check that everything looks OK and that no major errors or issues were identified. You should now have a working serial version of AmberTools19 installed and ready to go. This time we’ll also cover the installation of the parallel version.

Assuming everything ran smoothly this should, after some time, end with a message similar to:

You are supposed to download and install openMPI 4.0.1 from source using a script found in $AMBERHOME/AmberTools/src called configure_openmpi. I did not manage to get this to work with macOS clang however it is supposedly accomplished running the commands outlined below. On any other system than macOS, the number of cores is likely found issuing another command then sysctl:

The last step that remains seems to be to install openMPI support for cpptraj to read and write NetCDF files in parallel. I did not manage to do this using clang so for this option, see the GCC instructions below. This is what the commands should look like:

Brew Gcc

However, this produces the following error for me:

Compiling AmberTools19(/Amber18) with Homebrew GCC

Assuming that you have already installed Xcode and CLT (otherwise go back to the start and take care of this right now) we shall now install AmberTools19(/Amber18) using Homebrew GCC 9.

The first thing you need to do is to give the Homebrew versions of gcc compilers priority over macOS clang alternatives. Even if you installed gcc 9 through homebrew, gcc will still be clang when you try to compile code using “gcc“. If this is a project of your own you can always just refer to gcc as gcc-9however this will not help is now as AmberTools(/Amber) will look for “gcc”. One simple way to reversibly accomplish this is to use symbolic/soft links:

Creating links in /usr/local/bin with correct names according to the OS. You might need to “exit” the terminal to reset the session and make sure that the correct compilers have priority. Running:

Should now return /usr/local/bin instead of /usr/bin, then you are set to go!

Once you no longer want these alternatives to be the default, just remove the links accordingly:

Assuming that you’ve downloaded AmberTools19 from the developers webpage and moved the compressed archive to the location where you want to install AmberTools19(/Amber18) you make your way through the filesystem in a Terminal(.app) session and execute the following commands:

After a while you should see something along the lines of:

After a successful installation you should run through the tests to see that everything is churning along correctly:

Brew Gcc Download

If this does not generate any larger problems you now have a functioning serial version of AmberTools19(/Amber18) installed and ready for use. I have previously terminated the write-up here though as I’ve made the decision to cut down on the alternatives for compilers I have instead provided information regarding the parallel installation as well. For this I elected to use the script ($AMBERHOME/AmberTools/src/configure_openmpi) which is available to help with the installatoin of opemMPI as the version provided by homebrew is built for clang and not gcc and I did not have the energy to build it from source by myself. You’ll get through these steps by doing the following:

You might need to reset you terminal session to make sure the correct openMPI installation is found (exit).

After some waiting and pacing you should se something similar to:

So assuming everything went well it is now time to runs some tests, this does not work for me. Potentially this depends on the fact that I’m using a work computer though what happens is that I get bombarded with “Allow network access” pop-ups for every test and some other annoying things. Theoretically, this is what you should do:

Replacing “X” with the number outputted by sysctl -h hw.ncpu | awk {'print $2'} to use all cores available.

Install Brew Linux

Remaining is to install openMPI support for cpptraj to deal with NetCDF files in parallel, which is accomplished with the following command:

After some more waiting:

Brew Gcc Menu

Again, you should run some tests though I am not able to do this as my OS does not allow me to run them. You should by now have a working parallel version of AmberTools19(/AMber18) ready for use.