Draft Forbes Group Website (Build by Nikola). The official site is hosted at:
License: GPL3
ubuntu2004
Here are some notes about how I configure Mac OS X.
MacPorts
MacPorts brings to Mac OS X many programs available on Linux. The programs are compiled from source, which means it can take a while to install everything and that they need the Xcode command line tools installed:
These are installed in /opt/local/
and to use them, you should add /opt/local/bin
to your initialization scripts. (I do this with various configuration files in my configurations project: see for example my ~/.environment_site
file.)
I do not like running these commands as root, so once I install MacPorts, the first thing I do is make everything owned by an unprivledged user (me).
This has a couple of complications (see rsync
below) but works well for the most part. If you do this, be sure to run port
without sudo which will be counter to the usual instructions found on the internet. If there is a permissions issue, then check where and deal with it on a case-by-case basis.
Alternatives
Homebrew provides a popular alternative. From what I can gather from various discussions, MacPorts is more stable, better designed, and more reliable. Some key points are:
MacPorts installs in
/opt/local
. In contrast, Homebrew puts everything in/usr/local
while also changing the permissions of everything in there to the single user running. This might make sense with a single user – and indeed is similar to what I do with permissions for/opt/local
, but apparently makes it much more difficult for multi-user machines. It also presents a security hazard and is bad practice. For me, this is an issue, because I expect everything in/usr/local
to be customize by me – stuff I install from source for example.MacPorts installs redundant but isolated libraries, so does not break when Apple updates things. In contrast, Homebrew uses system libraries. Makes it smaller, but less robust.
Discussions
Useful Commands
See Common Tasks for more details.
Information:
Marking ports as requested (so they don't appear as leaves)
Marking ports as requested (so they don't appear as leaves)
Updating and Cleaning
Here is what I typically install:
Or, all of them:
The rsync
package needs access to /Library/LaunchDaemons
.
Cleaning
To clean your installation you might want to do the following:
According to this answer, you might also be able to delete the following:
After installation, my typical setup consumes about 1.7GB of disk space – most of which is due to ffmpeg
:
Dependencies
Custom Portfiles
If you need to create your own Portfile
or slightly modify an existing one you can quite easily by creating your own Local Portfile Repositories. Here is how I did this using a local repository in ~/src/ports
to edit the sshuttle
Portfile to depend on Python 3.9 (so MacPorts only brings in one version of python).
Add
file:///Users/mforbes/src/ports
to/opt/local/etc/macports/sources.conf
.Create the Portfile:
Edit the
Portfile
:Update the index:
Update the port and clean:
Shell (bash)
Sometimes one might like to use another shell instead of /bin/bash
. For example, one might like to use the version /opt/local/bin/bash
provided by MacPorts so that one can use the bash-completion
package. To do this, we first install the shell, then enable it, finally we change the user shell:
The for completions, I do things like:
Finally, in my ~/.bashrc
file, I have:
Startup Scripts
To see exactly what happens when you run bash
, you can do the following:
To see the nature of your shell, you can run echo $0 $-
. The first $0
will show you the shell being run, while the latter $-
shows the current set of options. Interactive shells will have i
in $-
, while login shells will have -
starting $0
For example, when you SSH to your computer you see:
The following sequence can be deduced for Mac OS X (see INVOCATION
in man bash
):
Interactive Login Shells – i.e. whenever you start a new Terminal window, or when you SSH in and start an interactive session, or when you call bash -li
:
/etc/profile
First of
~/.bash_profile
,~/.bash_login
,~/.profile
. (Inhibit withbash --noprofile
.)On exit:
~/.bash_logout
Interactive non-Login Shells – i.e. when you run bash
after opening a terminal:
~/.bashrc
Non-Interactive, Non-Login Shells - i.e. when you run a command with bash -c <cmd>
or run a command with SSH:
$BASH_ENV
: I.e. nothing in general, but you can trigger loading of a file with something like:
XCode
XCode is huge (~10GB), so I remove it (just drag XCode.app
to the trash) and just keep the command line tools installed:
After agreeing to the licence, you should see
Note: after you do this you will likely see the following warning from MacPorts:
Conda
In install Conda with the following in mind:
I use Miniconda as opposed to the full Anaconda: see Anaconda or Miniconda? distribution. If I need Anaconda, then I install it in a special environment.
I install Conda as the
conda
user so that I can't accidentally muck up the environments. This simulates what happens on HPC compute clusters etc. where we share conda environments.Note: I originally tried to use the
admin
account for this role, but this caused problems because administrators get added to theadmin
group, and then have some permissions in the conda environment that confuseconda
into thinking that it can write to the package directory, which it can't. Conda relies on this to switch to local installs.ARM issues: Some python libraries are not yet available for the ARM platform. In these cases, we need to create an environment with the
osx-64
subdir.Environments are specified with
environment.yml
files and Picky for Conda should be used to lock these.Custom work should be done in a virtual environment that sits on one of these base conda environments.
Here is the complete setup process:
Create a
conda
user account. (Probably easiest just to use the GUI.)I was going to enable passwordless
su
access, but it seems easier just to enable anssh
alias:Now copy the keys:
Create the base environments:
Create some specialized environments. Ideally these should be able to be created from my anaconda channel:
If you are updating them, it is useful to have them locally:
Networking
To see your MAC address:
If you need to change it, then you can spoof it with
Note: make sure that en0
is the correct device. You might want to check the ouput of ifconfig
first to see that this is indeed the active device.
VPN
To connect to various services at WSU, I downloaded their Global Protect client. This is needed for some reason. In particular, without using the VPN, the following does not work:
then on my Mac:
Without VPN, I can only send about 4 messages in either direction, then the connection hangs. Not sure why.
Wireshark
Wireshark is a full-featured debugging tool for networks. I install it and add it to the PATH so I can use it in a terminal.
SSH
To allow SSH acces to your mac (i.e. from one account to another) the Admin should go to System Preferences/Sharing and enable Remote login.
To tell KeyChain to remember your SSH keys do the following:
Note: It is important to make sure you use the Apple version of ssh-add
here and not something installed by port
, conda
, etc.
SSH Tunnels (SOCKS/VPN)
This will forward all traffic through the specified host. See https://superuser.com/a/757974. sshuttle
can be installed with pip
or macports
.
BBCP
Related to SCP is bbcp
which can be downloaded for OS X here. This is a fast tool for transferring files. I just copy it to /usr/local/bin/bbcp
.
LaTeX
I install the MacTeX which puts most things in /usr/local/texlive
and also includes BibDesk, Skim etc. When you upgrade from one year to the next (say 2017 to 2018), the new installation will be placed in /usr/local/texlive/2018
leaving the old version in /usr/local/texlive/2017
. These can be big (~5.4GB) so you might want to move the old version off your hard-drive (but keep it for a bit in case things go wrong.)
Once you upgrade, you may need to make a few changes to keep things working, setting the path for the LaTeX programs. These should be set to
but might need to be updated. Check in the preferences of the following packages if things do not work as expected:
BibDesk: (Seems okay with symlink above.)
TeX Live: (Needed path refreshed as it seetermsn to usoe thMe absolute path, but can refresh this for you if you confirm.)
LaTeXiT: (Seems okay with symlinks.)
Safari
Extensions
Ad Blocking: There are several extensions that block ads.
AdBlock: I have been using this and am reasonably happy with it. The blocking of ads in YouTube is especially valuable.
AdBlock Plus: Another alternative that is almost the same (small UI differences).
AdGuard for Safari: Was recommended in an uBlock issue about Safari. Does not block YouTube ads, but I have not tried the full AdGuard (just the browser extension).
For a comparison of the first two, see AdBlock vs AdBlock Plus.
StopTheMadness: Some websites disable useful features such as copy and paste. This extension claims to restore this functionality.
I used a different approach - temporarily disable JavaScript. This can be done under the Safari
Develop/Disable JavaScript
menu item, but I also enabled a shortcut ⌘J to Disable JavaScript..
Emacs
There are several options for using Emacs on Mac OS X:
GNU Emacs for Mac OS X: I use this. It is a fairly generic version of emacs with traditional key bindings. The only annoyance is that one must use Esc for the Meta key. (
M-x
is achieved by "pressing and releasingEsc
, then pressingx
.)Aquamacs: This more tightly integrates with the OS X interface, but is significantly slower.
Configuration
I install the following packages using the Options/Manage Emacs Packages
menu option. Note, there are three main package archives. I use these with the following preference: 1) gnu
, 2) marmalade
, 3) melpa
(see this discussion for more details.
Editing Features
autopair
: Automagically pair braces and quotes like TextMate.org
: Outline-based notes management and organizer.
Modes:
auctex-latexmk
: Add LatexMk support to AUCTeX.haskell-mode
: A Haskell editing mode.lua-mode
: A major-mode for editing Lua scripts.markdown-mode+
: Extra functions for markdown-mode.markdown-preview-mode
: Markdown realtime preview minor mode.markdown-toc
: A simple TOC generator for markdown file.yaml-mode
: Major mode for editing YAML files
Elisp Debugging (init files)
benchmark-init
: Benchmarks Emacs require and load calls.bug-hunter
: Hunt down errors by bisecting elisp files.use-package
: A configuration macro for simplifying your.emacs
.
Git: (I don't really use these, but they were recommended at some point.)
git-commit-mode
: Major mode for editing git commit messages [github].git-rebase-mode
: Major mode for editing git rebase files [github].magit
: A Git porcelain inside Emacs.
Python: Modes for working with python.
conda
: Work with your conda environmentspython-mode
: Python major mode. This has some major problems when using Tramp for remote editing, so I do not use it any more.elpy
: Emacs Python Development Environment
Web/Blog:
sass-mode
: Major mode for editing Sass files.scss-mode
: Major mode for editing SCSS files.json-mode
: Major mode for editing JSON files.jinja2-mode
: A major mode for jinja2.tidy
: Interface to the HTML Tidy program.
I load these in my .emacs
file with the following code
BBEdit and .plist Files
BBEdit is another editor with one killer feature - the ability to decode and edit Apple binary property list (.plist
) files. One can edit these with XCode (if you install it all), convert it with plutil -convert xml1 config.plist
, or use defaults write com.apple....
, but it is much easier just to open it with BBEdit.
iPhone/iPad
Backups
If you make backups of your iPhone or iPad with iTunes, you can locate these with
iTunes/Preferences/Devices/Device Backups
and right-click toReveal in Finder
.
These files, however, are not organized and obfuscated. To interpret this data you seem to need to use a third party application. Most of these have a demo mode that will allow you to view the files, but put severe limitations on how much data you can actually extract without paying.
iPhoneBackupViewer: View photos, but must save them one at a time.
Useful Applications
GPG
This is useful for encryption and signing files. I use the vi plugin which allows you to edit encrypted files.
https://www.vim.org/scripts/script.php?script_id=3645
Simply move the
gnugpg.vim
script into~.vim/plugin
:
Preference Panes
Choosy: A "browser" that redirects websites to specific browsers. I am just trying this, but hope to use it to open CoCalc websites exclusively in Chrome for example even though I generally prefer Safari.
MultiBrowser: A similar "bowser" to Choosy that allows you to select which browser to open a link with. Make this your default browser, then you can choose whenever you open a URL. I have been using this for a while and it works quite nicely. Choosy might be better in that it allows you to specify rules, but MultiBrowser is very simple and works well.
Vagrant
Docker
I installed the Docker App for OS X. It seems like one can install this without root access (opening it as an unprivileged user says it will "create symlinks in ~/.docker/bin
" instead of /usr/local/bin
which requires root access.
After installing as admin, I ran Docker.app
and then went to the Preferences and changed the location of images to /data/apps/Docker
. This fails, and apparently one needs to create a symlink:
I had to do this as a user. Force-quitting all docker processes using Utility Manager, then moving via Finder worked.
(Docker has an option for excluding from Time Machine backups, but I use SuperDuper!)
CoCalc
One can run CoCalc locally using the [CoCalc Docker image][]. This takes about 25GB.
This should run CoCalc locally so you can access it via
Note: you might run into certificate issues. You can allow HTTPS for localhost in chrome by going to
and selecting Allow invalid certificates for resources loaded from localhost.
[CoCalc Docker image]: https://github.com/sagemathinc/cocalc-docker#cocalc-docker-image
AWS-CLI
I don't really use Docker on my Mac, but install it so I can provision images on AWS. To do this I did the following:
Make a directory for installing the
aws-cli
without sudo:Download and install the
aws-cli
as a local user ("Install for Me Only").Install the Docker App for OS X. Note: I though I could use
port install docker docker-machine
and save on some disk space, but this needs Vagrant, so no clear savings there. There are some relevant discussions in this direction though:
Disk Space:
Docker uses lots of space. Some can be reclaimed with:
Environment Modules (Lmod)
To maintain some coherence with HPC environments, we install some version of the Environment Modules package. Here we use the Lmod variant as this is used on our local cluster.
To use these, I add the following to my ~/.environment_site
file:
For details about what these do, see my modules configurations folder.
Graphics
MacSVG
Program for producing SVG graphics.
GIMP
Opensource replacement for Photoshop.
CMake
Needed by some applications (I needed it to build VisIt plugins. I simply added this line to my environment_site
file:
Julia
Some tools - in particular the diffeq library - use Julia, but it is not so easy to install via Conda. I install the native application. After installing I had to link it:
Then, using julia:
Note: If this fails, you might need to manually clone the registry:
Then, in python, I needed to:
This installed everything needed into ~/.julia
.
References
Sound: Black Hole
I used to use SoundFlower to route audio on my Mac. This is no longer supported, but they recommend Loopback. Another option is BlackHole as discussed in this article. JACK is another option (this is used by Audacity – a great open-source tool for editing audio.)
LICEcap
Simple program for capturing activity on your screen and turning it into an animated GIF. Useful for demonstrating how to use an interface.
Sim Datlonism
Color-blind simulator. Useful for checking graphs, posters, etc.
Microsoft Office
I have the problem of running with fairly limited disk space, so installing the complete Office suite was prohibitive. For a long time I stuck with Microsoft Word for Mac 2011, which I got from the department. It appears now that individual apps are available through the App Store:
Synergy
I have Synergy which allows me to control different computers on my network with one keyboard and mouse.
AVG
I install AVG for virus protection. I don't enable the continuous monitoring, but scan files before I install them.
NPM
I install NodeJS from the downloads page and extract the macOS Binary in /data/apps/node
, then add /data/apps/node/bin/
to my path.
Update npm
with:
Monterey
Here is how I setup my new M1 Macbook Pro. This is a university-owned computer (purchased with my NSF grant) so I keep my personal account separate from my work account.
Partitioned HD with one Container 'Macintosh HD' and a Volume 'Data'. The idea is to allow quick backup of the OS to previous hard-drives (256GB partitions), putting easily installable data on the separate partition. Note: Using separate partitions is a mistake as it precludes fixing things if you run out of space.
Install OS from scratch (only use migration assistant later for the user account. Recommended several places.)
Create admin account: (Disallow Apple ID to reset this password.)
Create a firm link for
sudo vi /etc/synthetic.conf
: adddata /Volumes/Data
.Create additional accounts:
wmforbes (work)
mforbes (personal - to be copied from old computer)
conda (for conda installations)
Hide from login:
sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add conda
Use Finder -> Get Info to give write permission to
/usr/local/bin
and/data/apps
where we will make symlinks.
Users should setup SSH access to
admin
andconda
if needed:
Change some preferences in System Settings:
Trackpad speed, scrolling direction, keyboard repeat rate, Fn key, Caps-Lock->Control).
Sharing and enable Remote login.
Security & Privacy/Firewall: Trying
Block all incoming connections
. Local SSH still works, but this will probably break AirDrop etc. (incoming is broken.)
Change shell to bash
chsh -s /bin/bash
.Create the following files:
Install Intego virus protection VirusBarrier from App store.
Install GNU Emacs for Mac OS X.
Install Markdown and YAML mode (so I can edit this file!)
Install Macports:
Change shell again:
Add path for all users of bash:
Install Lmod:
Install TexLive with MacTeX. To reduce disk space, I first linked the install directory to
/data/apps/texlive
:
Reboot.
Install Conda as conda: On a shared system where many people might need to administer conda environments, we would have a separate account, but for a single-user computer we can use admin.
One could use conda to provide environments for basic pythons, but becuase of the need for
libssl
which is provided by MacPorts, we use it instead. If you want to use Conda, do this:As admin, link these:
Install Apps:
Extensions:
Also for Firefox, Chrome, and Safari. (Needs to be done on each account.)
Twilio Authy. Use the desktop version which needs Rosetta (the App store version does not work well on OS X - too klunky.)
https://www.vim.org/scripts/script.php?script_id=3645
Move the
gnugpg.vim
script into~.vim/plugin
for all users.
App Store:
Intego VirusBarrier (done earlier)
GoodNotes 5
Notability
KeyNote
Pages
GoPro Player.
OneNote.
One of the components was not properly installed, and after chatting with Tech Support, I fixed it by opening Applications/Wacom Tablet/.Tablet and dragging WacomTouchDriver to System Preferences/Security & Privacy/Privacy/Input Monitoring/. (I needed Command+Shift+. to show the hidden folder).
LICEcap: For making screen captures as animated gifs.
Mumble: Communication (we run a server on Swan).
Issues
Apple only allows applications from trusted developers to run. This causes a problem with MacPort installed programs after some virus scanners are run. To get around this, you can add
/opt/local
to your virus scanners list of Trusted files. Retroactively you can run something like this as admin:For example,
port install python38
will give a problem after running Intego's VirusBarrier Scanner app.Some version of python require earlier versions of libssl leading to the warning:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
and subsequent errors. (Especially during testing with [Nox][].)
We get the libraries like libssl from MacPorts, so we use this to provide the various versions of python rather than conda.
Catalina
I did a fresh install of Mojave then upgraded to Catalina. Here is what I did afterwards:
System Preferences:
Apple ID -> App Store: Disable Password for Free Downloads.
Dock -> "Automatically hide and show Dock"
Disable Siri.
Keyboard -> Keyboard -> Key Repeat = Fast, Delay = Short, Use F1, ... as function, Modifier Keys -> Caps Locks = Control.
keys.
Text -> Disable smart quotes.
Dictation On.
Trackpad -> Scroll & Zoom: Disable scroll-direction "Natural"
Accounts:
Make conda
and admin
accounts. I have the following in my ~/.ssh/config
file:
This allows me to login with ssh admin
.
XCode:
MacPorts:
Download MacPorts.
Applications:
AVG:
LastPass: Download from the webpage, not the App Store.
Firm Links:
Catalina and later do not permit users to make files in root like /data
. However, one can create a "firm link". I make a separate Data
volume then create the following file as admin: sudo vi /etc/synthetic.conf
:
then reboot.
Conda:
I keep the /data
tree in ~admin
, so first we create the conda
folder:
Now we install Conda etc.
I downloaded Miniconda and installed it in the ~admin/data/conda
.