2024-09-27
This note describes how I use OS X as a programmer's tool, for
Every developer uses different tools and has different preferences. Other programmers may need other tools and processes; most of them are supported on OS X. (These notes are based on my current use of OS X 14.5, Sonoma.)
What makes a Mac good for programming?
Many of these programming tools run in a Terminal shell window, which allows you to type Unix commands.
You have to install tools in the right order, because some tools depend on others. See the installation section for the latest operating system for a step by step cookbook.
These notes apply to Snow Leopard through Sonoma.
Apple provides a complete free set of system development tools free with OS X. Install them from the Internet. In a Terminal window, type xcode-select --install. (In Ventura and Sonoma, this queues a request to install the tools using , which you then invoke.)
The tools include C and C++ compilers, all the Unix tools like Perl, rsync, make, etc.
You can also install Apple's programming development environment including Xcode, header files, documentation, and auxiliary tools. (A free subscription to Apple Developer lets you download additional tools and information for developing Mac and iPhone applications.)
Use the man command in a Terminal window to get standard Unix help.
One of the first things I do is to create a directory called /bin in my home directory, and then tell the system to search $HOME/bin for commands, as well as the standard places that Unix-derived systems look. This allows tools I add to my /bin to be used in scripts. To set this up, type the following in a Terminal window:
cd $HOME mkdir bin echo "export PATH=$HOME/bin:$PATH" >> .bash_profile . .bash_profile
(My .bash_profile is more complicated: if running on MacOS, it also does some ssh-add comamnds and sets up Homebrew.)
I keep personal shell scripts, Perl programs and modules, and utilities in a subdirectory ~/bin of my home directory. There are over 300 files there. Some of these tools have been incrementally tweaked and developed over more than 30 years, on whatever system I was using at the time. (Probably half are obsolete.) When I need to write a new tool, I often start from an old one and modify it. (This can be a time saver, but risks the propagation of programming errors.) What I always say is: "If it's worth doing, it's worth writing a tool that does it."
As described in my CPAN page, I ensure that Perl programs in ~/bin have a first ("shebang") line #!/usr/local/bin/perl, and then create a symlink from /usr/local/bin/perl to /opt/local/bin/perl.
For shell scripts in ~/bin, I make the ("shebang") line #!/bin/sh. This tries to make sure that my personal scripts are executed by a shell that works the same way on all Unix descended operating systems. (In 2008, some of my shell scripts were broken by Ubuntu 6.10 when they changed /bin/sh to dash... see https://wiki.ubuntu.com/DashAsBinSh. So things can still go wrong.)
See Setting Up SSH Keys for the steps to generate your ssh keys to enable access to other computers without giving a password every time, and advice on using rsync.
I set my Terminal shell to bash. This is standard on most Linuxes. When bash starts, it invokes $HOME/.bash_profile.
My .bash_profile adds /usr/local/bin:/opt/local/bin:/opt/local/sbin to the PATH for Homebrew, adds $HOME/.cargo/bin to the PATH for Rust, adds /usr/local/opt/ruby/bin to the PATH for Ruby, puts my $HOME/bin at the head of PATH to override any other programs, invokes ssh-add for keys to remote systems (ssh-agent will start automatically), then calls ...
.bashrc which runs $HOME/bin, then executes $USER.bashrc which defines my personal bash macros and invokes ...
$USER.bvars which defines variables local to the computer, like server names.
I also create $HOME/.inputrc which sets terminal behavior for the Bash shell. My preferences are:
set bell-style none set completion-ignore-case On set mark-symlinked-directories on
I saved default Terminal settings so that when I launch Terminal I get three shell windows with different colored backgrounds. These help me remember what I am doing when I multi-task.
As of Big Sur, the default Terminal shell was changed to zsh, but I have not reworked my environment yet. bash still works as of Sonoma. Converting bash configuration to zsh is complex.
In Terminal Settings, I set the Window profile tab settings to show the command key, working directory path, and active process name in the window headeer. I set scrollback to "limit to available memory."
In Finder, I set View Options to open in list view, and make that the default. In Finder Settings, I customize the sidebar and show all filename extensions.
I am learning Go and Rust, using the environments provided by the languages.
Emacs is my text editor of choice and has been for over 30 years. I use Aquamacs Emacs, derived from Emacs 24 and adapted to the Mac by David Reitter, and customize its settings to be like Emacs on other platforms.
Homebrew provides hundreds of Open Source Unix tools compiled for OS X, free. It can be used to install the latest versions of important programmer's tools, such as rsync.
I use Homebrew to install uni2ascii, ImageMagick, subversion, psutils, Perl, Go, Ruby, rsync and other Terminal commands. (Some of these tools come with the Mac, but Homebrew may install a newer version.)
ImageMagick is a free package of image processing programs. I install it with Homebrew. One thing I use it for is automatically generating thumbnails for picture galleries. Another task is generating packed sprite files: see CSS Sprites.
MySQL is a free relational database, now owned by Oracle. I install it with Homebrew (see above). It is straightforward to download and install on the Mac. Among other uses, I create web pages such as the indexes for this website by loading a database with tabular information and then generating HTML from a MySQL query. Oracle bought MySQL some years ago: the Open Source program MariaDB is compatible.
Perl is a wonderful quirky text processing language. Perl is free and included with Mac OS X system tools (though Apple gives you an old version; get a better one from Homebrew). I have written many personal tools in Perl and used them on multiple platforms. Perl is also useful for writing server-side web applications.
CPAN, the Comprehensive Perl Archive Network, is a free community-provided library of Perl programs. To install Perl modules, open a Terminal window and do sudo -H cpan and then issue CPAN install commands.
Some CPAN bundles I use are Bundle::CPAN, DBI, DBD::mysql, Crypt::CBC, Crypt::Twofish, Net::DNS, Net::Subnet, News::NNTPClient, Geo::IP::PurePerl, Digest::SHA, Compress::Raw::Zlib, Compress::Raw::Bzip2, LWP::Simple, XML::Simple
(Install Homebrew before CPAN, and update your environment, before installing CPAN modules. If you are installing DBD::mysql, install MySQL first.)
Apache is a widely used and powerful web server, included in OS X. It is useful for testing web applications before deploying them on a server. You can add features to it by editing its configuration files in /etc/apache2. Apache is shipped with OS X but not enabled in Lion and later versions. See the instructions for each macOS release to see how to turn it on.
PHP, Python, and Ruby are scripting languages, no longer supported by OS X. Installing them from Homebrew if you need them. You can enable their use in Apache by editing the Apache configuration files.
Inkscape is a free drawing tool oriented toward vector graphics. You can draw with illustration tools and export files in many formats. You can use it to trace a bitmap graphic and then output SVG.
I install HTML Tidy 5.8.0 from Homebrew; it supports HTML5.
A drawing tool oriented toward diagrams and charts is very useful. OmniGraffle Pro is slick (I like it better than Microsoft Visio on Windows, or trying to draw in PowerPoint).
If you are doing web development with graphics, you may be able to avoid spending the $120/yr that Photoshop costs from Adobe. You can get a free version of GIMP for OS X, or buy Adobe Elements or Affinity Photo.