Appendix D — macOS
Using Unix/Linux on macOS offers a unique and powerful environment with macOS’s Terminal, but it’s important to be aware of the differences and limitations inherent in macOS’s implementation of Unix. Below we cover some special considerations rooted in macOS’s distinct architecture and its version of Unix.
macOS Terminal
The default Terminal app on macOS provides a solid interface to access the Unix command line, but there are other terminal emulators available (like iTerm2) that offer additional features such as split panes, search, and customization options.
macOS Shell
macOS has transitioned from using Bash as the default shell to Zsh since macOS Catalina. While both are Unix shells, they have some differences in features and configuration files (~/.bash_profile
for Bash vs. ~/.zshrc
for Zsh).
To change the default shell on macOS from zsh
to bash
, follow these steps:
Verify that Bash is installed and locate its path.
which bash
This gives you the path to the Bash executable, typically /bin/bash
.
Change the default shell using the
chsh
(change shell) command.chsh -s /bin/bash
Replace /bin/bash
with the path you found if it’s different.
When prompted, enter the user account’s password.
Verify the default shell has been changed to Bash by restarting the Terminal and entering:
echo $SHELL
The output should now be /bin/bash
Considerations
macOS Versions
In newer versions of macOS, Zsh is the default shell. If you’re switching to Bash, it’s important to know that some of the default configurations and behaviors may differ
Terminal Preferences
If you’re using iTerm2, you might have a specific shell configured in the profile settings which could override the system default shell setting. To ensure your iTerm2 sessions open with Bash, check the preferences (iTerm2 > Preferences > Profiles > General > Command) and set it to /bin/bash
.
Homebrew
Homebrew is an essential package manager for macOS, filling the gap for Unix/Linux software that isn’t pre-installed on macOS. It allows users to easily install and manage additional Unix tools, GNU utilities, languages, and applications. Learning to use Homebrew will significantly expand the Unix/Linux tools at your disposal on a macOS system.
BSD vs. GNU Commands
macOS is based on Darwin, which incorporates elements from BSD Unix. Therefore, some of the command-line tools on macOS behave differently from their GNU counterparts found in Linux. For example, options and flags for commands like ls
, sed
, and tar
may vary. This means that while the overarching principles remain the same, specific command syntax and options might require adjustments or the use of GNU versions of commands (installed via Homebrew, for instance).
Case Sensitivity
By default, the macOS file system (APFS or HFS+) is case-insensitive but case-preserving. This behavior is different from most Linux file systems, which are case-sensitive. This can affect scripts and commands that rely on case distinctions for file and directory names.
Security and Permissions
macOS has implemented increasingly stringent security measures, including the System Integrity Protection (SIP) and sandboxing mechanisms, which can restrict access to certain files and system operations. While these features enhance security, they can also limit what you can do via the Terminal. Understanding macOS’s security model and permissions (such as using sudo
wisely) is crucial.
Filesystem Hierarchy
While the Unix filesystem hierarchy is preserved in macOS, there are macOS-specific directories and structures, such as ~/Library
for user-specific application support files and preferences. Understanding these macOS-specific elements is important when navigating and managing files via the Terminal.
Networking and Interoperability
macOS integrates well with both Unix/Linux and Windows environments, supporting various network protocols and file sharing options out of the box. Commands like ssh
, scp
, and smbutil
can be used for remote access and file transfers, making macOS a versatile platform for learning Unix/Linux networking basics.
Graphical Applications
macOS allows Unix command-line tools to interact with its graphical user interface (GUI) applications in ways that are not typically available on other Unix systems. For instance, the open
command can be used to open files or applications, and osascript
can interact with AppleScript-enabled applications for automation.