To modify the PATH environment variable, you can follow these steps:
Temporary Modification
To temporarily add a directory to PATH for the current session, use the following command:
export PATH=$PATH:/new/directory/path
Replace /new/directory/path with the actual path you want to add. This change will last only for the duration of the terminal session.
Permanent Modification
To make the change permanent, you need to add the export command to your shell's configuration file. Here’s how to do it for common shells:
-
Bash:
- Open
~/.bashrcor~/.bash_profilein a text editor:nano ~/.bashrc - Add the following line at the end of the file:
export PATH=$PATH:/new/directory/path - Save the file and exit the editor.
- Apply the changes by running:
source ~/.bashrc
- Open
-
Zsh:
- Open
~/.zshrc:nano ~/.zshrc - Add the same export line as above.
- Save and exit, then run:
source ~/.zshrc
- Open
-
Other Shells:
- For other shells, check the appropriate configuration file (like
~/.profilefor sh).
- For other shells, check the appropriate configuration file (like
Verify Changes
To verify that the PATH has been modified, you can run:
echo $PATH
This will display the current PATH, including any new directories you added.
