Zsh: Permission Denied When Using Flutter Commands (flutter doctor, upgrade)? Fix Guide for .zshrc & PATH Issues
If you’ve switched to Zsh (Z shell) for its powerful features like auto-completion, themes, and plugins, you might have encountered a frustrating error when running Flutter commands: zsh: permission denied: flutter. This error typically arises when Zsh can’t properly locate the Flutter SDK or lacks the necessary permissions to execute its binaries.
Whether you’re trying to run flutter doctor, flutter upgrade, or any other Flutter command, this guide will walk you through diagnosing and fixing the root causes—most often misconfigurations in your .zshrc file or issues with your system’s PATH environment variable. By the end, you’ll have a clear understanding of how Zsh interacts with Flutter and how to resolve permission-related roadblocks.
When Zsh throws zsh: permission denied: flutter, it means one of two things:
Zsh cannot find the flutter executable (due to a misconfigured PATH), OR
Zsh found the executable but lacks the permissions to run it (due to file/directory permission issues).
This error is distinct from zsh: command not found: flutter, which indicates the flutter binary isn’t in your PATH at all. Here, "permission denied" suggests Zsh found the binary but can’t execute it—often due to incorrect file permissions or a PATH pointing to a restricted directory.
Before diving into fixes, let’s identify the most likely culprits:
Incorrect PATH Entry in .zshrc:
The PATH environment variable tells Zsh where to look for executables. If your Flutter SDK’s bin directory isn’t in PATH, or is misconfigured (e.g., pointing to the parent flutter folder instead of flutter/bin), Zsh can’t find the flutter command.
Missing Execute Permissions on Flutter Binaries:
The flutter executable (located in flutter/bin/flutter) must have "execute" permissions (chmod +x) to run. Without this, even if PATH is correct, Zsh will deny access.
.zshrc Not Sourced After Changes:
If you modified .zshrc but forgot to reload it (with source ~/.zshrc), Zsh won’t recognize the updated PATH.
Flutter Installed in a Restricted Directory:
Installing Flutter in system directories like /usr/local/ or /opt/ without proper permissions (e.g., using sudo for installation but not for execution) can cause permission issues.
Typos or Syntax Errors in .zshrc:
A missing colon, extra space, or typo (e.g., fluter instead of flutter) in the PATH entry will break the configuration.
Check PATH for existing entries: Run echo $PATH to see if Flutter’s bin directory is listed. Look for paths like /home/yourusername/flutter/bin or /Users/yourusername/flutter/bin.
If PATH doesn’t show it: Use which flutter to locate the executable. If this returns flutter: command not found, search manually:
# Search your home directory for the Flutter SDKfind ~ -name "flutter" -type d | grep "flutter$"
Common install locations: ~/flutter, ~/development/flutter, or ~/Documents/flutter.
The .zshrc file (located in your home directory: ~/.zshrc) is where Zsh loads environment variables like PATH. Let’s check for Flutter-related entries.
Run this command to inspect the flutter binary’s permissions (replace /path/to/flutter with your SDK path):
ls -la /path/to/flutter/bin/flutter
You should see output like:
-rwxr-xr-x 1 yourusername yourusername 12345 Jun 1 12:00 flutter
The first three characters (rwx) indicate the owner has read, write, and execute permissions. If you see -rw-r--r-- (no x), execute permissions are missing.
Avoid system directories like /opt/ or /usr/local/ for Flutter. Installing in your home directory (~/flutter) ensures you have full permissions without sudo.
"Permission denied" errors with Flutter in Zsh are almost always due to PATH misconfiguration, missing execute permissions, or restricted install directories. By verifying your .zshrcPATH entry, ensuring the flutter binary has execute permissions, and installing Flutter in a user-owned directory, you can resolve the issue quickly.
Remember to source .zshrc after edits and test with flutter doctor to confirm success.