macOS for physicists
It is no secret that MacBooks have long been a popular choice of personal computers among physicists. When the cosmologist Hitoshi Murayama wrote, almost ten years ago, what was perhaps the first iteration of the sort of article you are currently reading, Macs had already become a favourite across several laboratories and physics departments around the world. His article was later updated by others, most notably by the incognito physicist going by the name ‘Flip Tomato’ (who also wrote this wonderful piece) and, more specifically for astrophysicists, by the cosmologist Edd Edmondson.
The last such article was written back in 2013 during the days when Mac OS X had just been overhauled and its name had been shortened to OS X. Today we have macOS which, like OS X, is a considerable overhaul of Apple's wonderful operating system in much more than name. However, no updated overview or guide for physicists getting started with (a new) Mac exists yet. This article is intended to serve precisely that purpose. Everything here has been tested on the current version of macOS, High Sierra.
Why use macOS?
Most of this is common knowledge but here is a rundown anyway. Windows is a bucketload of custom, proprietary code. This is a crude way to put it but it is what it is and Windows is ridden with problems with smooth operation and reliability[^ I know this statement is bound to polarise opinions so if you have had a good experience with Windows, more power to you. Nobody I know has had the same, unfortunately.]. By contrast macOS is built atom the XNU kernel (which also powers iOS, tvOS etc.) which in turn carries with it UNIX facilities. This makes a huge difference: the XNU kernel that runs macOS, the UNIX framework, and the operating system called Darwin which is based on these codes are all freely available.
The end result is that UNIX is something physicists have been considerably familiar with over several years and macOS coupled that with the Darwin Graphic User Interface, called Finder, to provide the best of both worlds: in macOS we have a smooth operating system with great visual character and efficiently designed functionality with the UNIX CLI (via Terminal.app) available for programming use being a single click away. Of course all this is to say nothing of the unmatched hardware Apple is known for.
Popular physicist Brian Cox, a longtime fan of Macs, says, ‘When you look around a physics conference now you see more Macs than anything else ... I think that's because they're essentially UNIX ... There's a huge code base. We're still using programs written in Fortran quite a lot—programs that were written in the ’70s and ’80s—and they compile directly on the Mac. It's very easy to do, as opposed to Windows, where it's just a pain to compile all the old legacy programs.’
Get started with Xcode
Earlier you could install OS X from a DVD but those days are behind us now. macOS gets annual major upgrades with minor updates almost every month, all for free and all over-the-air. Almost all new Macs come with a recent version of the operating system installed. This is convenient but takes away some control at the installation stage that might have otherwise been appreciated. However the solution is not more complicated by any measure.
The first tool to install is Apple's own Xcode. It is available for free from the App Store. Xcode is an IDE and carries a bunch of files you need to make your mac programming-aware. It loads headers, libraries and compilers you need for most languages you will need—C, C++, Objective-C, JAVA, Python, Ruby, Cocoa, Apple's own Swift and much more—all in one application. If you want to use Pascal and Perl, for example, free third-party add-ons to Xcode can make it happen in no time.
As a last step after installing Xcode open terminal.app and say
sudo xcodebuild -license and accept the Xcode license.
Your next stop will be setting up your Mac for TeX. There is a quick install possible with a lightweight version of TeX, including only select packages, called MacTex Basic and although you may be tempted to install that its lack of packages will eventually prove to be a pain in the neck. Choose instead to download the entire TeX library via the complete MacTeX package. It has been packed as a .pkg for macOS and will install everything you need and create an easily accessible TeX tree. To locate your tree simply
kpsewhich -var-value TEXMFHOME on a terminal.app window.
Once you have your TeX installation ready make sure you keep it updated via
tlmgr update --self through the Terminal. You can also use something with a GUI like TeX Live Utility to keep your TeX tree updated with CTAN. If you are not comfortable with the terminal, or if you are looking for efficiency, there are several front-ends available for TeX with great GUIs. TeX Shop is probably your best free option while Texpad is the one I personally use[^ Texpad costs money but is worth every penny. It even lets me, via Texpad connect, sync tex files across my Macs and iPad to work while on the go.]. TeX Shop seems rough around the edges but works great; Texpad will be more in line with your Mac experience: ‘we've designed the UI to meet high expectations of Mac users’ says their website.
Get a package manager
Physics-y stuff is helped a great deal by package managers. In Prof Murayama's original article he recommends Fink. I doubt anyone really prefers this anymore[^ A lot has changed since Prof Murayama's article was first published. This is a particularly telling sentence: ‘The Xcode is big, though, weighing more than 800MB. Don't attempt a download without a broadband.’ Today Xcode is almost 5.5 GB in size.]. MacPorts and Homebrew are much better alternatives. Homebrew is my personal choice. Of course Fink is the oldest so there may be many who prefer it merely by habit but you can hardly go wrong with either of these.
MacPorts comes with a straightforward .pkg installer. Installing Homebrew is no less straightforward but perhaps considerably more fun. Open terminal.app and say
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)". Some interesting packages to install are imagemagick, ghostscript and, if you like, xdvi. Most GUI-based document and image handling, though, is built into the incredibly powerful Preview.app on macOS.
Emacs or VIM
Some may argue that I was hasty in jumping from Xcode to TeX to a package manager without ever talking about VIM or another Emacs alternative (and they may be correct) but rest assured that there is a reason for it: Macs come with Emacs built in so, to be honest, you really have nothing to do here. That said, if for some reason—say habit—you are in search of a more familiar interface you can always opt to use VIM which also comes pre-installed. Simply say
vim at the terminal prompt.
But we now come to the catch. Emacs that comes with your Mac does not support X11 which any physics student will have encountered as part of a computing laboratory course with gnuplot or some equivalent graphing software[^ Sometimes I wonder if x11 is the only thing common among all physics courses worldwide.]. That is why I led with a package manager before talking about Emacs.
x11, gnuplot and such
I wrote a guide some years ago when I was a student myself that, for my excitement, seems to have been linked to from a couple of universities. I will save myself the trouble of re-writing that but in the old article you can find four steps to install gnuplot that also installs x11 and any other terminal you may like. These instructions use Homebrew.
According to Prof Murayama's article x11 used to be available straight from the OS X installation disc. I know of no such arrangement available in the current OTA update cycles of macOS. The steps in the article linked to above are your best bet to get set-up with x11 on your Mac.
Do you and a colleague have a Mac? Is your colleague not using their Mac for high-intensity activity at the moment? Do your eyes water when you see all their CPU cycles going waste? Fear not, you can harvest their CPU power by hooking up all your Macs to the Xgrid cluster.
In all seriousness though, if you have kept up with past macOS updates you will know that I led with a joke: Xgrid is dead. Apple now offers macOS server instead and for $20 from the App Store you can harness the power of multiple Macs in your department or laboratory and set-up a joint workgroup, share data locally, set up a mail server, a DNS and what-have-you, all from the comfort of your office. With enough Macs you can have your own multi-CPU supercomputer.
You can also use it for simpler tasks besides analysing particle beams. CERN, for instance, allows installation of several institution-level applications (LabVIEW, hpglview, Mathematica, Octave, Matlab and more) right on its local macOS Server cluster (both general purpose and mathematical) rather than from the cloud.
If your Mac is strictly for personal use you need not worry about macOS Server.
Some nerdy packages
Besides computational and condensed matter physicists, astrophysicists and particle physicists port packages most often. This world is therefore filled with packages for such fields. If you followed instructions to install Homebrew above you will enjoy David C. Hall's HEP tap. While you are cloning repositories off Github you might be interested in my LaTeX class for lecture notes (that comes with Italian translations thanks to S. Maggiolo).
Also try IDL and IRAF if you are into astrophysics. Since COMSOL and other such applications are costly for mortal individuals you can test out alternatives like FEniCS or MOOSE (warning: installation procedure is not for the faint-hearted) that help accomplish similar end goals.
Finally this somewhat old-looking but still valid webpage contains lots of applications and data for High Performance Computing on macOS. You may not have to follow up with many alternatives since the page seems to have been updated at least as far as OS X Sierra.
The 'usual' stuff
Although it is fancy to
pwd your way from time-to-time with the Terminal and
open -a "application" ~/path/to/file instead of using the GUI like puny normal human beings that is not how most of us use our personal computers. We use it for checking our e-mails and calendars and notes and reminders and for typing up reports and articles and making presentations and what not. For all these you need nothing fancy; all macOS installations come with Pages, Keynote, Numbers, Mail, Reminders, Notes, Calendar, Preview, Grapher, Dictionary, Contacts, Time Machine, Keychain and, of course, the all-powerful Textedit among other applications. Resist the urge to download alternative apps. For most of us, even though we may not like to admit it, these stock apps work just fine.
Lastly, as a physicist I must mention gaming. Prof Murayama says of 'usual' apps on a Mac, ‘For presentations, Apple's Keynote is rapidly gaining popularity. It allows PDF graphics without losing scalability, has cool transitions. Steve Jobs himself uses it for MacWorld keynote addresses ... I haven't had much problem finding good applications for research purposes. People complain that there are still less games available for Macintosh, that may be a good thing. ^_^’
Today there are thousands of games for Macs, both on the App Store and on platforms like Steam. My lazy pastime is Civilisation VI. For a quick fix my friend and colleague introduced me to Real Boxing. For leisure unrelated to gaming Handbreak is good for DVD/CD authoring, Cyberduck for FTP, and my focussed writing app of choice is Ommwriter.
Finally, for a bit of nostalgia, if you grew up in the 80s and 90s playing Dos games try Dosbox or, better yet, Boxer to emulate a Dos environment on your Mac. If you need game suggestions my favourites are Dave (where you play Dave), Prince (the predecessor to the modern Prince of Persia series), Skyroads (roads in the sky, what more can I say?) and Biomenace (shooting up alien and saving hostages across cities, forests and laboratories). That is enough nostalgia for the day.
Have fun with your Mac, fellow physicist.