To change the order of directories in your PATH environment variable, you can modify it in your shell configuration file. Here’s how to do it:
For Bash Users
Open your terminal.
Edit your
.bashrcor.bash_profilefile (usually located in your home directory):nano ~/.bashrcor
nano ~/.bash_profileModify the
PATHvariable by adding or rearranging directories. For example, to add/usr/local/binat the beginning:export PATH=/usr/local/bin:$PATHSave the file and exit the editor (in
nano, pressCTRL + X, thenY, andEnter).Apply the changes by running:
source ~/.bashrcor
source ~/.bash_profile
For Zsh Users
If you are using Zsh, you would typically modify the .zshrc file:
Open your terminal.
Edit your
.zshrcfile:nano ~/.zshrcModify the
PATHvariable similarly:export PATH=/usr/local/bin:$PATHSave and exit, then apply the changes:
source ~/.zshrc
Verifying Changes
To verify that your PATH has been updated, you can run:
echo $PATH
This will display the current order of directories in your PATH. Adjusting the order allows you to control which executables are found and executed first.
