To add a directory to the PATH environment variable permanently, you can follow these steps:
Open your terminal.
Edit your shell configuration file:
- For
bash, you typically edit~/.bashrcor~/.bash_profile. - For
zsh, you edit~/.zshrc.
You can use a text editor like
nanoorvim. For example, to edit.bashrcwithnano, run:nano ~/.bashrc- For
Add the export command: At the end of the file, add the following line, replacing
/path/to/directorywith the actual path you want to add:export PATH="$PATH:/path/to/directory"Save and exit the editor:
- In
nano, pressCtrl + O, thenEnterto save, andCtrl + Xto exit. - In
vim, pressEsc, type:wq, and hitEnter.
- In
Apply the changes: To apply the changes to your current session, run:
source ~/.bashrcor for
zsh:source ~/.zshrc
Now, the specified directory will be included in your PATH permanently, and you can run executables from that directory from any location in the terminal.
