4 Ways to Fix “command not found: claude” or “claude is not recognized”

Encountering a “command not found” error immediately after installing a new tool is a common hurdle for developers and system administrators. You might have just finished installing Claude Code on Linux only to find that your terminal refuses to launch the application. This usually happens because the terminal cannot locate the executable file, or the installation process did not properly register the binary in your system’s environment.

Whether you are working in a Bash shell on Ubuntu or using PowerShell on Windows, the system relies on a specific list of directories to find commands. If the Claude CLI isn’t in one of those folders, or if your shell hasn’t been refreshed to recognize the new path, you will see the “not recognized” warning. This guide provides four practical methods to troubleshoot and fix this issue so you can get back to using the complete Claude Code CLI.

Key Takeaways: Fixing Command Recognition

  • PATH Variable → The most frequent culprit; the system needs to know exactly which folder holds the claude executable.
  • Installation Verification → Ensures the package actually exists on your storage before you attempt to run it.
  • Shell Refresh → Vital for applying changes to .bashrc or .zshrc without restarting your computer.
  • Administrative Privileges → Some global installations require you to understand the sudo command to set correct permissions.

Method 1: Verify the Installation Path

Before adjusting settings, confirm where the claude binary was placed during installation. Most CLI tools installed via package managers like npm are placed in a global bin folder.

Command: npm list -g @anthropic-ai/claude-code (if installed via npm)

If the command returns “empty” or “not found,” the installation failed. In this case, you should follow the complete guide to Claude Code to reinstall the package correctly.

Method 2: Update the System PATH Variable

The PATH variable is a string that tells your OS where to look for executable files. If you installed Claude to a custom directory, you must add that directory to your path.

Linux Steps:

  1. Open your configuration file: nano ~/.bashrc.
  2. Add the following line at the end: export PATH=$PATH:/home/username/.npm-global/bin (Adjust based on your actual install path).
  3. Save and exit.

Expected Result: After updating the path, the shell will search your new folder every time you type “claude”.

Method 3: Refresh the Shell Configuration

Changes to your environment variables don’t take effect in currently open terminal windows unless you manually source the configuration file.

Command: source ~/.bashrc

See also: Mastering the Linux Command Line — Your Complete Free Training Guide

Output: The terminal will return to a blank prompt. You can then verify the command is found by running: which claude

This should return a file path like /usr/local/bin/claude rather than an error message.

Method 4: Check File Permissions

Sometimes the file exists, but the user does not have permission to execute it. This is a common security feature in Linux environments.

Command: ls -l $(which claude)

If the output does not show an “x” (e.g., -rw-r--r--), you must change file permissions to make it executable: sudo chmod +x /path/to/claude


Step-by-Step Process: A Clean Re-Installation

If the methods above fail, a clean reinstall often resolves hidden pathing conflicts:

  1. Remove existing files: Use your package manager to uninstall.
  2. Verify disk space: Check file size in Linux to ensure you have room for a fresh install.
  3. Install as Global: Run npm install -g @anthropic-ai/claude-code.
  4. Audit the PATH: Run echo $PATH to see if common bin folders are listed.
  5. Restart Terminal: Close and reopen your terminal app.
  6. Test: Type claude --version to confirm success.

Summary Table

IssueRecommended FixPurpose
Missing BinaryRe-run installationEnsures files are on disk.
Path ConflictUpdate PATH variableTells OS where to look.
Shell Lagsource ~/.bashrcApplies changes immediately.
Denied Accesschmod +xGrants execution rights.
Wrong Versionnpm update -gEnsures compatibility.

FAQs

Why does “claude” work with sudo but not as a regular user? This indicates a permission issue or that the PATH for the root user includes the binary while your local user PATH does not. Check your local .bashrc settings.

Do I need to reboot after fixing the PATH? No, using the source command as shown in Method 3 allows you to apply changes without a full system restart.

Can I use an alias instead? Yes, you can add alias claude='/full/path/to/binary' to your shell config if you prefer not to modify the entire PATH variable.


Related Posts

David Cao
David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

Articles: 633

Leave a Reply

Your email address will not be published. Required fields are marked *