Mac Terminal
What is the Mac Terminal. How to use the Mac Terminal, configure the shell, and set up a macOS development environment.
For programming on a Mac, the essential tool in your development environment is the Mac Terminal application. The Terminal is a command-line interface (CLI) that allows you to interact with the operating system and run commands. The Mac Terminal application or console gives us access to the Unix command line, or shell.
Before you get started
Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.
Other software you may need
It's good to know about other software tools you might use. In addition to Warp Terminal, I recommend:
- Zed Editor for an AI-enhanced text editor
- Arc Browser for a newer web browser
- ChatGPT desktop application for better ChatGPT usability
To set up a development environment for programming, you can install:
- Xcode Command Line Tools for missing command line tools
- Homebrew as a software package manager
- Git for version control
- programming languages such as Python and Ruby
What's Here
This article introduces basics so you can get started.
- How to find the Mac Terminal
- Alternatives to Mac Terminal
- What is the shell
- How to run commands in the Mac Terminal
- Navigating the file system with the Mac Terminal
- Configuring the shell
- Environment variables
- Editing files from the command line
- How to quit the Mac Terminal
- Getting the prompt back
- Advanced shell frameworks
- Xcode Command Line Tools
- Homebrew package manager
Also see:
How to find the Mac Terminal
First, you'll need to know how to open the Mac Terminal. There are two ways to open the Mac Terminal.
- Click the Spotlight icon in the menu bar and type “terminal.”
- Look in the
Applications/Utilities/
folder for the Terminal application.
See How to Open Terminal in Mac for detailed instructions.
Alternatives to Mac Terminal
Although Apple provides its own built-in Mac Terminal application, many developers install iTerm 2, Warp Terminal, Alacritty, WezTerm, or many others. Additionally, some text editors or integrated development environments (IDEs), such as Visual Studio Code, include an integrated terminal application. I've compiled a list of Mac terminals to download with a comparison of features and recommendations.
What is the shell
Zsh, the Z shell, is a program that runs in the Mac Terminal, interprets Unix commands, and interacts with the operating system. You are using the shell when you enter commands in the Terminal window.
Zsh is the default shell program on newer Macs. The original Bourne shell (sh
) and other shells (Zsh, Bash, Fish, Ksh, Tcsh) are similar for a beginner. They differ when it comes to more complex scripting for automation and customization aspects. Prior to macOS 10.15 Catalina, the Bash shell was the default in Mac Terminal.
The shell contains several basic commands such as cd
(change directory). Other commands are external to the shell and implemented as executable programs provided by Apple and stored in the file system, typically in directories like /bin
or /usr/bin
. For example, when you run ls
, the shell looks for the ls
file in these directories and runs it as a program.
Run commands in the Mac Terminal
To run commands in the Mac Terminal, or execute programs on the command line (phrases that mean the same thing), you'll type commands at the Terminal prompt and then press the Enter key (also known as Return).
Commands follow a specific syntax, typically command [options] [arguments]
. While options (or flags) modify the command's behavior, arguments are the targets of the command, like filenames.
Flags are a type of option that acts as an on/off switch (or "toggle"). They are typically one-letter and preceded by a single dash (-
). Options can be short (one-letter with a dash) or long (word-length with two dashes). For example, --verbose
is a long option that might be used in commands to provide more detailed output.
You can typically see all the options for a command by entering the command followed by --help
(two dashes and "help".)
$ <command> --help
Navigating the file system with the Mac Terminal
You can navigate through your Mac's file system using the command line interface (CLI), an alternative to navigation using the Finder's graphical user interface (GUI). Commands like cd
(change directory) let you move within the file system. Commands like cp
(copy), mv
(move), rm
(remove), and mkdir
(make directory) manage files and directories.
Configuring the shell
The shell can be customized with various options. Some features, such as aliases or a custom prompt, are for convenience. Other features, such as environment variables, are essential to make programs available or change program behavior.
There are several different configuration files and it's often perplexing to figure out where aliases and environment variables should be stored. Most configurations are set in either ~/.zprofile
or ~/.zshrc
. The article .zshrc or .zprofile explains the differences. See Shell Configuration for a full guide.
Environment variables
Many programs require settings to customize what they do. Settings for a program are passed as options or flags but also may be set as environment variables. These environment variables act as default settings which are set when launching the shell.
Almost everyone needs to set the $PATH
environment variable. It sets the directories that the shell searches for executable files. If you install a new program for use from the command line, you'll likely have to adjust the $PATH
environment variable. The $PATH
is typically set in the ~/.zprofile
file. See the guide Mac PATH for instructions.
Editing files from the command line
You can edit plain text files such as zsh configuration files using any text editor, including the Mac's TextEdit. See the guide Mac Text Editors for more.
How to quit the Mac Terminal
As you know, you can quit GUI software on the Mac from a menu or using ⌘-q
(CMD+q). But anyone new to the Mac Terminal often gets stuck when they want to quit a command line program. You can always quit the Terminal with ⌘-q
(CMD+q). But often you just want to exit a command line program without quitting the Terminal.
To quit a program from the command line and restore the prompt, you need to enter this:
CTRL-c
Press the C
key while holding down the Ctrl
key on your keyboard. This sends a signal to the shell to end the current running process.
There's more to quitting, if you want to be an expert. Some programs will ignore CTRL-c
. You can open another terminal window and enter the command ps
to see a list of running processes. sorted by PID
or process identifier. Then you can kill any process by entering kill PID
where PID is the process id. But often it's easier to just quit the Terminal with ⌘-q
(CMD+q).
Getting the prompt back
Some command line programs display a wall of text output and wait to see if you want more. For example, a command may display partial output and stop when the terminal window is full. If you see a :
colon character, CTRL-c
may be ignored. Pressing Enter
may display the next line, pressing Space
may output more, and entering q
may quit the program and restore the prompt.
Advanced shell frameworks
When you first encounter terminal commands, it's best to keep things simple. Focus on learning basic terminal commands; you'll also need to learn to set environment variables.
Skilled programmers and system administrators often install an advanced shell framework, such as Oh My Zsh, to manage Zsh configuration. Oh My Zsh is complicated and confusing for beginners but you may encounter developers who love it and urge you to try it. If you have the urge to customize your shell with a colorful custom prompt or a collection of aliases, you might be ready for Oh My Zsh.
Xcode Command Line Tools
Out of the box, a Mac doesn't contain all of the software and tools needed for programming. Apple's installable package, Xcode Command Line Tools, provides the most-needed utilities for software development. You can install this package directly from the Terminal application or as part of installing Homebrew, the popular Mac package manager.
Homebrew package manager
Homebrew is a package manager for macOS. It is one of the first tools you'll need when you set up a local development environment for programming on a Mac. Use it to install software programs for the terminal. It is like an app store for programming tools (but everything is free). MacOS includes some pre-installed programming languages and command line utilities but most work requires newer versions of languages and tools not provided by Apple. You can view instructions to Install Homebrew (which requires setting the $PATH
environment variable).
Resources
Most developers know how to use a terminal application and basic Unix file commands to move around the computer. If Unix is new to you, you can use your file browser to create files and move around, picking up Unix as you go. To learn a little Unix, I recommend either Learn Enough Command Line to Be Dangerous or Zed Shaw’s free Command Line Crash Course to gain confidence with Unix shell commands.
What's next
My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.