Linux / BSD Shell Doesn’t Recognize Newly Installed Binaries

If you have installed a new binary on your Linux or BSD system and the shell doesn’t recognize it, it’s likely because the binary is not in your system’s PATH. Here’s how you can add the directory containing the binary to the PATH:

  1. Determine the directory that contains the binary. For example, if you installed a new binary called foo in the directory /usr/local/bin, the directory to add to the PATH would be /usr/local/bin.
  2. Open your shell’s configuration file with a text editor. The name and location of the configuration file depends on the shell you are using. Here are the files you should edit for common shells:
    • Bash: ~/.bashrc or ~/.bash_profile
    • Zsh: ~/.zshrc
    • Korn shell (ksh): ~/.kshrc
    • C shell (csh): ~/.cshrc

    For example, if you are using the Bash shell, open the ~/.bashrc file with a text editor:

    nano ~/.bashrc
  3. Add the following line at the end of the file, replacing /path/to/binary/directory with the directory that contains the binary you installed:
    export PATH=$PATH:/path/to/binary/directory

    For example, if you installed the binary foo in the directory /usr/local/bin, you would add the following line:

    export PATH=$PATH:/usr/local/bin
  4. Save and close the file.
  5. Reload the configuration file for your shell:
    • Bash: source ~/.bashrc
    • Zsh: source ~/.zshrc
    • Korn shell (ksh): source ~/.kshrc
    • C shell (csh): source ~/.cshrc

    For example, if you are using the Bash shell, reload the configuration file with the following command:

    source ~/.bashrc
  6. Try running the binary again. It should now be recognized by the shell.

That’s it. You should now be able to run the newly installed binary from any directory on your Linux or BSD system.

Leave a Comment