Mac Tree Command: Install tree and Fix Command Not Found
November 11, 2026 · 9 min read
Mac Tree Command: Install tree and Fix zsh: command not found
The Mac tree command isn't there until you install it. macOS ships without tree, so Terminal answers with zsh: command not found: tree. Run brew install tree to get it. If the error survives the install, your shell can't see Homebrew's folder yet. This guide covers both fixes, the useful flags and no-install fallbacks.
Why Your Mac Says zsh: command not found: tree
tree is a small open-source program written by Steve Baker, and Apple doesn't bundle it with macOS. We checked on macOS 26.4: there's no tree in /usr/bin or in any other folder on the default PATH. So the first time you type it, the shell searches every folder in your PATH, finds nothing and gives up. Windows does bundle a tree, but the Windows tree command is a different program with its own switches.
The exact wording depends on your shell. Since macOS Catalina (10.15), zsh is the default shell, so most people see the first line below. Older accounts that still run bash get the second.
zsh: command not found: tree
-bash: tree: command not found
Before installing anything, check whether some copy already exists:
command -v tree
which tree
Both print a path such as /opt/homebrew/bin/tree when tree is available, and print nothing (or an error) when it isn't. And yes, macOS has a full command line: open Terminal from Applications, then Utilities, and you're in a zsh session.
How to Install the tree Command on a Mac With Homebrew
Homebrew is the standard way to add command-line tools to a Mac. For most people, it's also the quickest way to get the tree command for Mac. If brew --version already prints a version, skip to the second block. Otherwise, copy the install line from brew.sh. As of November 2026 it reads:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The script explains each step and pauses for confirmation before it changes anything. On a fresh Mac it may also install Apple's Command Line Tools for Xcode, which can take a few minutes. When it finishes, install tree and confirm it works:
brew install tree
tree --version
The tree formula shipped version 2.3.2 at the time of writing, so tree --version should report 2.3.2 or newer. On Apple Silicon Macs running a supported macOS version, Homebrew installs a prebuilt binary, so the whole step usually takes seconds.
Homebrew also handles the rest of tree's life on your Mac. Run brew upgrade tree to pick up a new release, brew info tree to see the installed version and where it lives, and brew uninstall tree to remove it. You never need sudo for any of these, because Homebrew owns its own folder.
Still Getting tree: command not found? Fix Your PATH on Apple Silicon
Seeing the tree command not found error right after a successful install is the case older tutorials never cover. On Apple Silicon Macs (M1 and later), Homebrew lives in /opt/homebrew, and /opt/homebrew/bin isn't on macOS's default PATH.
Since mid-2025 the installer adds it system-wide in /etc/paths.d/homebrew when your account has admin rights, but only new Terminal windows pick that up. Older installs and installs without admin rights depend on a line in your shell profile, so without it both brew and tree come back as not found.
Homebrew's installer prints that line under "Next steps", but it's easy to scroll past. Here it is for zsh:
-
Check your PATH with
echo $PATH. If/opt/homebrew/binis missing, carry on. -
Add Homebrew's environment setup to
~/.zprofile, the file zsh reads at login:echo >> ~/.zprofile echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv zsh)" -
Open a new Terminal tab, or run
rehashin the current one so zsh rebuilds its table of known commands. -
Run
tree --versionagain.
The last line of the block applies the change to your current window straight away. Older guides show brew shellenv without the trailing zsh; current Homebrew accepts both. Bash users put the same line in ~/.bash_profile with bash instead of zsh, and use hash -r in place of rehash. The Homebrew installation docs warn that Homebrew won't work if you skip these directions.
Intel Macs differ. Their legacy Homebrew prefix is /usr/local, and /usr/local/bin is on the default PATH, so the error there usually means tree really isn't installed. Homebrew now lists every Intel Mac setup as Tier 3, its lowest support level, and the current installer runs only on Apple Silicon.
Installing tree With MacPorts Instead
If you already use MacPorts, you don't need Homebrew as well. One command does it:
sudo port install tree
MacPorts packages the same upstream tree and installs it under /opt/local/bin. You could keep both package managers, but we'd pick one so your PATH stays predictable.
How Do You See the Folder Tree on a Mac?
Type tree on its own to print everything below the current folder. On a large folder, that output scrolls for a while. Pass a path and a depth limit to keep it readable.
tree -L 2 my-site
That prints two levels of my-site, then a count of what it found:
my-site
├── docs
│ └── setup.md
├── package.json
└── src
├── app.js
└── utils
3 directories, 3 files
These flags cover most day-to-day use on macOS.
| Flag | What it does |
|---|---|
-L 2 | Stop after two levels |
-d | Show folders only |
-a | Include hidden files (names starting with a dot) |
--dirsfirst | List folders before files |
-h | Show human-readable sizes |
-n | Turn colour off |
-o tree.txt | Write the output to a file |
One Mac quirk: with -a you'll see .DS_Store files in many folders Finder has opened. Add -I '.DS_Store' to hide them. The same -I option takes other patterns for skipping folders such as node_modules. Our Linux directory tree guide goes deeper on exclude patterns, and the same flags work on a Mac.
Mac Tree Command Alternatives That Need No Install
On a work Mac where you can't install software, the built-in BSD find and sed can fake it. This alias has circulated for over a decade:
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
It's a decent stand-in for the tree command Mac users usually install, but it has real limits. It only works on the current folder, has no depth control, and includes every hidden file. We tested this function in zsh on macOS 26.4. It accepts a folder and a depth, and skips dotfiles:
lstree() {
(cd "${1:-.}" && find . -maxdepth "${2:-2}" -not -path '*/.*' |
sed -e 's;[^/]*/;|____;g;s;____|; |;g')
}
Paste it into ~/.zshrc, open a new tab, and run something like lstree ~/Documents 3. Inside the sample project, lstree . 3 prints:
.
|____docs
| |____setup.md
|____package.json
|____src
| |____utils
| | |____format.js
| |____app.js
The catch: entries come out in whatever order the file system returns them, not alphabetically, and there's no file count. For a quick look without any formatting, ls -R lists each folder's contents in turn.
Copying tree Output on macOS for Docs and Chats
macOS includes pbcopy, which sends anything piped into it to the clipboard. Combine it with tree:
tree -L 2 -n --noreport | pbcopy
tree doesn't colour output sent through a pipe unless something forces it, but -n makes sure no colour codes slip in. --noreport drops the summary line. Paste the result into a fenced code block tagged text so the lines stay aligned. Fenced blocks keep spacing and line breaks exactly, as our Markdown code block guide explains. Our README guide covers the other sections a good README needs. To read that README back in Terminal, see our roundup of terminal Markdown viewers.
Rather Skip Terminal? Build the Folder Tree in Your Browser
Some managed Macs block Homebrew, and some people would rather not open Terminal at all. In either case, the directory tree generator runs in your browser instead. Choose or drop a folder and it reads the file paths in the browser without uploading them, skipping node_modules, .git and build folders. You can also paste an indented list, an existing tree or a list of paths.
It outputs box-drawing lines, ASCII, a Markdown list or tree-style text. Very large folders are capped, so point it at the part of the project you care about. We prefer brew install tree on any Mac you control, and the browser tool on a locked-down work machine.
Once tree is installed and your PATH includes Homebrew, the Mac tree command behaves just like it does on Linux, because it's the same upstream program. Keep tree -L 2 --dirsfirst handy for quick maps and the lstree function for machines you can't change. When the result belongs in a README, paste it into a fenced block in the editor. It's free and runs in your browser with no account needed.