How to add a directory to PATH permanently?

To add a directory to the PATH environment variable permanently, you can follow these steps:

  1. Open your terminal.

  2. Edit your shell configuration file:

    • For bash, you typically edit ~/.bashrc or ~/.bash_profile.
    • For zsh, you edit ~/.zshrc.

    You can use a text editor like nano or vim. For example, to edit .bashrc with nano, run:

    nano ~/.bashrc
  3. Add the export command:
    At the end of the file, add the following line, replacing /path/to/directory with the actual path you want to add:

    export PATH="$PATH:/path/to/directory"
  4. Save and exit the editor:

    • In nano, press Ctrl + O, then Enter to save, and Ctrl + X to exit.
    • In vim, press Esc, type :wq, and hit Enter.
  5. Apply the changes:
    To apply the changes to your current session, run:

    source ~/.bashrc

    or 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.

0 Comments

no data
Be the first to share your comment!