The error message "export: command not found" in Linux means the `export` command, used to set environment variables for current sessions, is missing. This typically happens when the command isn’t recognized because the shell (e.g., Bash, Zsh, Fish) lacks access to the correct executable—often due to a misconfigured or incomplete installation of core shell utilities. The fix is straightforward: ensure the shell’s PATH includes the directory where `export` resides (usually `/bin` or `/usr/bin`).
What You'll Need
- A Linux terminal (any distribution: Ubuntu, Fedora, Arch, etc.).
- Administrator or root access (if reinstalling core system tools).
- A working internet connection (for package updates).
Step-by-Step
- Check which shell you’re using: Run `echo $SHELL` in the terminal to confirm your shell (e.g., `/bin/bash`). If unsure, note the output and proceed accordingly. If that didn’t work: Open a new terminal window (some shells cache commands). If still unresolved, proceed to step 3.
-
Verify `export` exists in core directories:
Search for the `export` binary with:
sudo find / -name 'export' 2>/dev/null**Expected output:** `/bin/export` or `/usr/bin/export` (though note: `export` is *not* a standalone binary—it’s part of the shell itself. The real issue is PATH misconfiguration. Instead, test if the shell commands work:echo $PATHIf no `/bin` or `/usr/bin` appears, the issue is PATH corruption. Proceed to step 4. If `find` returns nothing: The shell’s base functions may be broken. Reinstall the shell (step 5). -
Manually add core directories to PATH:
Open your shell’s configuration file based on the output from step 1:
~/.bashrc(for Bash)~/.zshrc(for Zsh)~/.fish_config(for Fish)
export PATH="/usr/bin:$PATH"Save the file, then reload:source ~/.bashrc(or the correct file for your shell). Verify: Test `export` again. If it still fails, the shell itself may be corrupted. -
Reinstall the shell (if PATH fixes fail):
As root, reinstall your shell’s package:
sudo pacman -S bash # Archsudo dnf reinstall bash # Fedora/RHELsudo apt install --reinstall bash # Ubuntu/DebianWarning: This may delete custom shell scripts. Test after reinstalling. -
Reinstall core system tools (last resort):
If the shell is still broken, reinstall the entire system’s core utilities:
sudo apt install --reinstall coreutils # Debian/Ubuntusudo dnf reinstall coreutils # RHEL/Fedorasudo pacman -S coreutils # ArchThis ensures `export` (and other shell commands) are restored.
Common Mistakes
- Editing the wrong shell config file: Verify the file path from `echo $SHELL` before editing. Some shells (e.g., Fish) require `export PATH` in their specific config (`~/.fish_config`).
- Forgetting to reload the config: Always run `source ~/.bashrc` (or equivalent) after adding PATH entries.
- Using the wrong PATH order: Append directories to `$PATH` *after* existing paths (e.g., `:usr/bin:$PATH`). Prepending can break existing commands.
- Assuming `export` is a standalone file: The error confuses `export` with the shell’s built-in variable functions. Focus on PATH or shell corruption.
- Skipping sudo for PATH changes: PATH edits to system directories (like `/usr/bin`) require root; user-only PATHs (e.g., `~/.local/bin`) are safer.
Tips
- Quick test for PATH issues: Run `type export` in Bash or `which export` in other shells. If it returns nothing, PATH is broken.
- Temporary fix (no config edit): Use absolute paths to commands (e.g., `/bin/echo`) until the shell is fixed.
-
Shell-specific notes:
- Zsh: Ensure `autoload -Uz compinit && compinit` is in `~/.zshrc` for full PATH resolution.
- Fish: Fish’s PATH handling is more flexible; test with `fish --version` after changes.
- Logical steps matter: Fix PATH before reinstalling shells/coreutils. A broken PATH can hide deeper issues.
Troubleshooting
If the command still fails after steps 1–4, try these advanced fixes:
- Check shell version compatibility: Run `bash --version` or `type -a bash`. Some older shells (e.g., Bash 4.x) may have PATH bugs. Update via package manager if needed.
-
Test in another terminal:
Open a new terminal window. If `export` works here but not your original session, the error is session-specific (e.g., tab completion or cache issues). Clear the session:
pkill -9 bash(kill stale Bash processes) or reboot. - Verify no PATH alias overrides: Run `type -a export` to see if aliases (e.g., `alias export='echo "Nope"'`) interfere. Remove or fix aliases in `~/.bashrc` or `~/.zshrc`.
- Check for corrupted shell environment: Run `env | grep -E 'PATH|SHELL'` to inspect critical environment variables. If `PATH` lacks `/bin`/`/usr/bin`, the system may need a deeper fix (e.g., reinstalling `coreutils` or the shell).
-
Last resort: Reset to default shell:
As root, reset to a minimal shell environment:
chsh -s /bin/bash(if using Bash) orchsh -s /bin/zsh(for Zsh). This wipes customizations but ensures a clean start.
Frequently Asked Questions
Why does "export" not work in my terminal?
The `export` command is a shell built-in, not a standalone binary. The error occurs when your shell’s PATH lacks the directory where shell functions reside (usually `/bin` or `/usr/bin`). This often happens after a partial system update or PATH corruption.
How do I permanently fix PATH issues?
Add `/usr/bin` to your shell’s PATH in `~/.bashrc` (or equivalent) with `export PATH="/usr/bin:$PATH"`, then reload the file. If that fails, reinstall the shell or coreutils.
Will fixing this break other commands?
No, if you append `/usr/bin` to PATH (after existing paths) or reinstall the shell, other commands (like `ls`, `df`) will remain unaffected.
Why does "export" work in one terminal but not another?
This suggests the issue is session-specific: a stale shell instance, cached settings, or a corrupted terminal environment. Try opening a new terminal or killing old processes.
Can I use a non-standard PATH, like `~/.local/bin`?
Yes, but for environment variables (which `export` manages), you must use system directories (`/bin`, `/usr/bin`) or ensure those paths are prioritized. User-only paths (like `~/.local/bin`) apply to *local* commands, not system-wide environment variables.
How do I debug which directory is missing from my PATH?
Run `echo $PATH` and look for `/bin` or `/usr/bin`. If missing, add them explicitly in your shell config file or reinstall core system tools.
If none of these steps resolve the issue, your system may have fundamental corruption (e.g., missing core libraries). In that case, back up data and reinstall the distribution.