Zit Seng's Blog

A Singaporean's technology and lifestyle blog

Setting Up Your Mac For Programming

The Mac may be more often associated with the fun stuff and the life stuff, if you know what I mean, but it’s also all good for work stuff, including programming and software development. You should know that, right? Many system administrators and programmers use Mac, so there must be something good with the Mac for these sort of work.

Working on Mac

The Mac, and OS X, will definitely serve as a great platform for programming. Some people may not realise that OS X is fundamentally built on a Unix-based operating system, so it’s also an excellent platform to learn about Unix (and Linux) as well as programming in a Unix-type environment. This is one of the reasons why I like OS X. In particular, for people who prefer to or are more comfortable working in Linux or other Unix-like operating system, OS X will prove to be a whole lot more likeable than Windows.

This post is an update to my 2012 post on Prepping Your Mac For Programming. It’s a useful read for any newcomer who’s thinking about or planning to do some programming on the Mac. Let’s get started.

First, you may be delighted to know that OS X already comes, out-of-the-box, with a Unix shell environment and plenty of command line tools the same as what you’d find in Linux and other Unix operating systems. The shell, or command line, is accessible via Applications → Utilities→ Terminal. Or, just spotlight (Cmd-Space) for Terminal. If you like, drag the Terminal app to your Dock, so that it’s more easily accessible in future.

OS X Terminal

The shell you get is a true-blue Bash shell. If you’re a seasoned Unix user, you’d feel completely at home, and I’m pretty sure you can figure out many things on your own from here. I’ll not attempt to write a dummies guide to the Unix shell here, so if you feel you need some hand-holding here, I’d suggest to Google for some Unix shell tutorials.

Many of the typical Unix command line tools are already included in OS X. For example, there are editors like vi (my favourite!) and nano. Scripting languages like Perl, PHP, Python, and Ruby are included. Then there are version control tools like subversion. There’s also git, but you’ll need to install the Command Line Developer Tools or Xcode mentioned later. You’ll feel totally at home if you came from a Unix programming environment.

If you need to login to a Unix host, or copy files back and forth, both ssh and scp are already in there. Oh yes, that means you don’t have to download another SSH client. You really don’t have to, because the default Terminal app in OS X already builds in a tabbed interface, connection bookmarks, and other sought after features.

There’s rsync too, if you need to keep directory trees in sync. There’s grep, and there’s find. Just like in Linux or Unix environment, there are man pages too, so you get help documentation on all the command line programs. Oh, for Perl programmers, of course perldoc is there.

What about compilers and, well, the real programming stuffs? Well, it’s a free download, or two, away. If you only want the command line compiler, linker, and other developer related tools, then just attempt to run gcc in the Terminal. OS X will prompt you to download the Command Line Developer Tools.

Screen Shot 2015-08-05 at 8.57.18 AM

Click on Install to only install the command line developer tools. Alternatively, you can install Xcode, a full Integrated Development Environment (IDE) from Apple. You can also directly install Xcode from the Mac App Store.

Xcode is pretty good as an IDE. It’s mainly used for developing OS X and iOS apps. With or without Xcode, you’ll get all the command line tools to build and debug C and C++ programs. Although the compilers are called gcc and g++, Apple has replaced the GNU Compiler Collection with their own Clang/LLVM suite. Xcode supports C, C++, Objective-C, Objective-C++, Java, AppleScript, Puthon, Ruby, Rez and Swift.

If you’re already familiar with the Eclipse IDE, you can get that on OS X too. The Eclipse IDE is pretty popular, so if you’re just starting out programming and looking to find an IDE to use, this is a reasonably good choice. Unless, of course, you are specifically looking at writing OS X or iOS apps, in which case I’d suggest to stick with Xcode.

To get your hands on 3rd party open source software like the way Linux distributions have package repositories, there are several solutions you can go with. The two most popular ones are probably Homebrew and MacPorts. They are fundamentally trying to do the same thing, but in different ways. I personally prefer Homebrew, because it keeps its stuff tidy and tries to use the native stuff in OS X as far as practicable. (There’s also Fink, by the way, yet another way to bring open source software to OS X.)

HomeBrew is easy to use. Suppose you prefer to use wget, instead of curl that comes with OS X. This is what you need to do:

$ brew install wget

That’s all there is to it. Notice that HomeBrew downloads and compiles from source code, so it’s a lot more like Gentoo than Ubuntu or CentOS. As you can make out in the screenshot below, HomeBrew also sorts out dependencies for you.

Screen Shot 2015-08-07 at 3.46.43 PM

I mentioned earlier that subversion and git are included in OS X. If you happen to prefer or need Mercurial, all you’ll need to do is type brew install mercurial. Check if your favourite software can be brewed with HomeBrew, type brew search <someprogram>. It’s that simple.

If you’re still living in X11 land, or dying for some Xterm, you’re in luck. The X11 server which Apple used to include in OS X until Mountain Lion, has been forked out to XQuartz, which is a free download. X11 development is probably not so common anymore, but if for any reason you needed to export a X11 display to your Mac, it works pretty well.

I’m pretty happy with scp. But occasionally, I must admit, it may be easier to do things through a graphical interface. I use ForkLift in these situations. ForkLift is a really capable dual-pane file management application that supports remote connections to FTP, FTP/TLS, SFTP, WebDAV(S), AFP, SMB and Amazon S3 servers.

Forklift1

Apart from the standard mode of accessing your files through ForkLift’s browser interface, you can also mount a remote server connection as a disk or volume. This feature is important to me. It enables access to remote server files as if they were simply connected to the Mac like a portable drive, so that other applications can simply read and write the files directly. It’s like how OS X’s Finder can directly connect to AFP and SMB shares, but this ForkLift feature adds on the ability to directly interact with, for example, an SFTP (i.e. SSH) server. As an example, notice that the folder, the one on the left pane containing the Camera Downloads subdirectory, in the screenshot of ForkLift above appears as a device in the screenshot of Finder below.

ForkLift-Finger1

ForkLift is not free. If you’re looking for cost-free solutions, there’s the veritable Cyberduck, which is also available for Windows. Cyberduck doesn’t have that mounting trick mentioned above. If you want that, you’ll need MacFusion. MacFusion only supports SFTP (SSH) and FTP.

Programmers too, not just system and network administrators, sometimes need to snoop on network traffic to figure out what is going on with their system or application. OS X has tcpdump. But if you’re looking for Wireshark, the successor to Ethereal in case you didn’t know, good thing it’s also available on OS X. At this time, the development version 1.99.8 will run natively without needing X11/XQuartz like the earlier versions required.

Wireshark

 

In OS X El Capitan (currently in public beta), the /dev/bpf* capture interfaces are readable by the logged in user, so you don’t need root privileges to run Wireshark. Sensible thing. Oh yes, there’s the /dev directory that Unix fellas are going to find familiar.

For Java developers, you can get the Java JDK from Oracle’s Java SE Downloads page. Mac OS X points you there if you try to run java or javac when they aren’t installed. Apple no longer includes Java in recent releases of OS X, but you can still download their old deprecated Java 6 runtime.

Web developers on the LAMP stack will find comfort in MAMP — that ubiquitous stack running on the Mac. Oh yes, your Mac can have Apache, MySQL, and PHP/Perl/Python. In fact, this is almost too simple. If you recall, PHP, Perl and Python are already in OS X. So too, is Apache httpd included. The only bit left is MySQL, which you can either build via HomeBrew, or download the MySQL binaries if you prefer.

I’m quite happy running the mysql command line client, but like ForkLift, sometimes it’s just easier to work with a graphical user interface. In this case, to talk to my MySQL server, I like to use Sequel Pro. It’s a whole lot more convenient, and it even does SSH tunnelling for me automatically.

Screen Shot 2012-08-12 at 9.26.45 AM

Despite its name, Sequel Pro is a free download, though they accept donations.

Both Android and Arduino have development kits on OS X as well. I play with them from time to time.

For those in the other editor camp, yes, emacs is there too. If you prefer a graphical type of programmer’s editor, but not quite dive into a full blown IDE, there’s textmate. You can build textmate yourself too, from sources available on GitHub.

By now, you should be getting the idea that Mac OS X is quite well supported, and hardly a forgotten land amongst programmers and the software development community.

The Mac offers a truly unique programming experience because it combines the best of two worlds. On the one hand, OS X provides a rich graphical experience with plenty of useful GUI apps. On the one hand, you get true blue Unix command line tools in a real Unix environment. It’s like Windows, but with a proper Unix environment; and it’s like Linux, but with a great GUI experience where everything just works.

Go forth and write killer apps!

2 thoughts on “Setting Up Your Mac For Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

View Comment Policy