How to modify PATH?

QuestionsQuestions8 SkillsProPermissions of FilesAug, 26 2025
0117

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:

  1. Bash:

    • Open ~/.bashrc or ~/.bash_profile in 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
  2. Zsh:

    • Open ~/.zshrc:
      nano ~/.zshrc
    • Add the same export line as above.
    • Save and exit, then run:
      source ~/.zshrc
  3. Other Shells:

    • For other shells, check the appropriate configuration file (like ~/.profile for sh).

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.

0 Comments

no data
Be the first to share your comment!