How to change PATH order?

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

  1. Open your terminal.

  2. Edit your .bashrc or .bash_profile file (usually located in your home directory):

    nano ~/.bashrc
    

    or

    nano ~/.bash_profile
    
  3. Modify the PATH variable by adding or rearranging directories. For example, to add /usr/local/bin at the beginning:

    export PATH=/usr/local/bin:$PATH
    
  4. Save the file and exit the editor (in nano, press CTRL + X, then Y, and Enter).

  5. Apply the changes by running:

    source ~/.bashrc
    

    or

    source ~/.bash_profile
    

For Zsh Users

If you are using Zsh, you would typically modify the .zshrc file:

  1. Open your terminal.

  2. Edit your .zshrc file:

    nano ~/.zshrc
    
  3. Modify the PATH variable similarly:

    export PATH=/usr/local/bin:$PATH
    
  4. Save 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.

0 Comments

no data
Be the first to share your comment!