AI · · 1 min read
Fixing 'command not found: claude' After Installing Claude Code
In this post
A quick troubleshooting guide for resolving
command not found: claudeby configuring your shell's PATH environment variable on macOS (Zsh) and Linux (Bash).
The Solution
Add the directory containing the Claude Code binary (~/.local/bin or npm global bin) to your shell's PATH.
1. Zsh (macOS Default)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
2. Bash (Linux Default)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Verify that the CLI is now accessible:
claude --version
Why This Happens
When you run a command in the terminal, the shell searches directories listed in the $PATH environment variable in order.
When installed via Anthropic's official script (curl -fsSL https://claude.ai/install.sh | bash), the binary is placed in $HOME/.local/bin/claude.
On many fresh macOS and Linux systems, ~/.local/bin is not included in the default $PATH, or the change has not yet propagated to your current shell session.
Diagnostic Checks
1. Identify Your Current Shell
Confirm which shell configuration file to modify:
echo $SHELL
/bin/zsh➔ Edit~/.zshrc/bin/bash➔ Edit~/.bashrc(or~/.bash_profile)
2. Verify Binary Existence
Check whether the executable was installed properly:
~/.local/bin/claude --version
If this prints the version number, the installation succeeded and only the PATH registration is missing.
3. If Installed via npm Global
If you installed via npm install -g @anthropic-ai/claude-code, ensure npm's global bin directory is in your PATH:
# Locate npm global bin
npm prefix -g
# Add npm bin to Zsh PATH
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Command Reference
export PATH="$HOME/.local/bin:$PATH": Prepends~/.local/binto$PATH, prioritizing local user binaries.source ~/.zshrc: Reloads the configuration file in your active terminal session without requiring a restart.
