Skip to content

Instantly share code, notes, and snippets.

@janAkali
Last active June 14, 2025 06:38
Show Gist options
  • Save janAkali/338e6bf143fcd0161a2f0d768b938e4b to your computer and use it in GitHub Desktop.
Save janAkali/338e6bf143fcd0161a2f0d768b938e4b to your computer and use it in GitHub Desktop.
How to add directories to PATH variable in every OS (for whole system, not limited to terminal).

Linux

Note: after editing files below - logout and login to apply changes.

  • Ubuntu, Debian, ArchLinux and most other ditributions:
    Open file ~/.profile in any editor and add your directory to PATH variable, for example:

    export PATH="$HOME/Documents/apps/bin:$PATH"

    If this doesn't work:

    • Bash login shell (default on most distributions):
      try ~/.bash_profile or ~/.bash_login or ~/.bashrc instead.

    • Zsh login shell:
      try ~/.zprofile or ~/.zlogin or ~/.zshenv

    • Tcsh, Csh login shell:
      try ~/.cshrc or ~/.login or ~/.csh.login

    • Fish login shell:
      add in fish config (usually ~/.config/fish/config.fish):

      set -ga PATH "$HOME/somedir" # append directory to PATH
      set -gp PATH "$HOME/somedir" # alternatively, prepend directory to PATH
  • OpenSuse Tumbleweed / Leap:

    1. Edit or create new system-wide file /etc/profile.local with root privileges, for example, in terminal:
      sudo nano /etc/profile.local
    2. Add your directory to PATH in /etc/profile.local:
      export PATH="$HOME/Documents/apps/bin:$PATH"

Windows (gist)

  1. The first step depends which version of Windows you're using:
  • If you're using Windows 8 or later, press the Windows key, then search for and select "System (Control Panel)".
  • If you're using Windows 7, right click the "Computer" icon on the desktop and click "Properties".
  1. Click "Advanced system settings".
  2. Click "Environment Variables".
  3. Under "System Variables", find the PATH variable, select it, and click "Edit". If there is no PATH variable, click "New".
  4. Add your directory to the beginning of the variable value followed by ; (a semicolon). For example, if the value was C:\Windows\System32, change it to C:\Users\Me\bin;C:\Windows\System32.
  5. Click "OK".
  6. Restart your terminal.

Edit system-wide file /etc/paths with root privileges. For example with terminal:

  1. Open Terminal
  2. Edit /etc/paths with nano:
    sudo nano /etc/paths
    1. Enter password when prompted
    2. Add the path you want to the top or bottom of the file
    3. Exit nano with control-x
    4. Press y and enter to save changes
  3. Restart your Terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment