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
:
- 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 thePATH
would be/usr/local/bin
. - 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
- Bash:
- 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
- Save and close the file.
- 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
- Bash:
- 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.