Close Menu
    Facebook X (Twitter) Instagram
    • About
    • Privacy Policy
    • Write For Us
    • Newsletter
    • Contact
    Instagram
    About ChromebooksAbout Chromebooks
    • Linux
    • News
      • Stats
      • Reviews
    • AI
    • How to
      • DevOps
      • IP Address
    • Apps
    • Business
    • Q&A
      • Opinion
    • Gaming
      • Google Games
    • Blog
    • Podcast
    • Contact
    About ChromebooksAbout Chromebooks
    How to

    How Can You Add a Directory to PATH in Linux

    Dominic ReignsBy Dominic ReignsJanuary 8, 2026No Comments4 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest

    Running commands in Linux requires the system to locate executable files. Programs like ls, grep, and find are stored in standard directories. However, scripts or programs stored elsewhere need the system to know their location. This is where the $PATH variable becomes essential. Adding a directory to $PATH allows you to execute programs from any location without typing full paths.

    What is the PATH Variable in Linux

    The $PATH variable contains a colon-separated list of directories. When you type a command, the shell searches these directories in order to find the executable file.

    View your current $PATH with:

    $ echo $PATH

    Example output:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    The shell searches directories from left to right. If two executables share the same name but exist in different directories, the shell runs the one found first.

    Note: The current working directory is not searched unless explicitly included in $PATH.
    Component Purpose
    $PATH Environment variable containing executable directories
    Colon : Separator between directory paths
    echo $PATH Command to display current PATH contents

    How to Check Your Current PATH in Linux

    Before adding directories to $PATH, verify what directories are already included.

    Use the echo command:

    $ echo $PATH

    Alternatively, use printenv:

    $ printenv PATH

    Both commands display the same information. The output shows all directories where the system looks for executables.

    To check where a specific command is located:

    $ which ls

    Output:

    /usr/bin/ls

    This confirms that ls resides in /usr/bin, which is included in $PATH.

    Add a Directory to PATH Temporarily in Linux

    Temporary changes affect only the current terminal session. Once you close the terminal, the modification disappears.

    Add a directory with the export command:

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

    This prepends $HOME/bin to $PATH. Programs in this directory now run without specifying the full path.

    Verify the change:

    $ echo $PATH

    The new directory appears at the beginning of the list.

    Tip: Place the new directory at the start of $PATH to prioritize it over existing directories.

    Why Temporary Changes Matter

    Temporary modifications are useful for testing scripts or programs before making permanent changes. They help avoid conflicts with system executables during development.

    Add a Directory to PATH Permanently in Linux

    Permanent changes persist across sessions. Store the export command in shell configuration files.

    For Single User (Bash)

    Edit ~/.bashrc for Bash users:

    $ nano ~/.bashrc

    Add this line at the end:

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

    Save the file and apply changes:

    $ source ~/.bashrc

    The directory is now permanently added to $PATH for this user.

    For Single User (Zsh)

    Zsh users should edit ~/.zshrc:

    $ nano ~/.zshrc

    Add the same export line:

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

    Apply changes:

    $ source ~/.zshrc

    For All Users (System-Wide)

    To add a directory for all users, edit /etc/environment:

    $ sudo nano /etc/environment

    Modify the PATH line to include your directory:

    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/custom/bin"

    Log out and log back in for changes to take effect.

    Warning: Editing system-wide configuration files affects all users. Verify changes carefully to avoid breaking executable access.
    Scope Configuration File
    Bash (single user) ~/.bashrc
    Zsh (single user) ~/.zshrc
    All users /etc/environment or /etc/profile

    Remove a Directory from PATH in Linux

    Removing a directory from $PATH requires editing the configuration file where it was added.

    Remove Temporarily

    Use sed to remove a directory for the current session:

    $ PATH=$(echo "$PATH" | sed -e 's/:\/home\/username\/bin$//')

    Replace /home/username/bin with the directory to remove. This change lasts only until you close the terminal.

    Remove Permanently

    Edit the configuration file where the directory was added. Open ~/.bashrc, ~/.zshrc, or /etc/environment and delete the corresponding export line.

    Apply changes:

    $ source ~/.bashrc

    The directory no longer appears in $PATH for new sessions.

    Note: Closing and reopening the terminal also removes temporary PATH changes.

    FAQs

    Use export PATH="$HOME/bin:$PATH" for temporary changes. For permanent changes, add the command to ~/.bashrc or ~/.zshrc and run source to apply.

    The shell executes the first match found. Directories are searched left to right in $PATH. Place higher-priority directories at the beginning.

    Edit /etc/environment or /etc/profile for system-wide changes. Modify the PATH line to include your directory and log out for changes to take effect.

    Run echo $PATH | grep "/your/directory" to search for a specific directory. If found, it appears in the output. Otherwise, the directory is not included.

    Yes. Use PATH=$(echo "$PATH" | sed -e 's/:\/path\/to\/remove$//') to remove a directory for the current session. Close the terminal to reset.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr
    Dominic Reigns
    • Website
    • Instagram

    As a senior analyst, I benchmark and review gadgets and PC components, including desktop processors, GPUs, monitors, and storage solutions on Aboutchromebooks.com. Outside of work, I enjoy skating and putting my culinary training to use by cooking for friends.

    Related Posts

    8tshare6a Software Download Guide

    February 10, 2026

    How To Use SFM Compile For Manual Model Conversion

    January 15, 2026

    How To Fix Winobit3.4 Software Error

    January 14, 2026

    Comments are closed.

    Best of AI

    Pephop AI Statistics And Trends 2026

    February 26, 2026

    Gramhir AI Statistics 2026

    February 24, 2026

    Poe AI Statistics 2026

    February 21, 2026

    Joyland AI Statistics And User Trends 2026

    February 21, 2026

    Figgs AI Statistics 2026

    February 19, 2026
    Trending Stats

    Chrome Incognito Mode Statistics 2026

    February 10, 2026

    Google Penalty Recovery Statistics 2026

    January 30, 2026

    Search engine operators Statistics 2026

    January 29, 2026

    Most searched keywords on Google

    January 27, 2026

    Ahrefs Search Engine Statistics 2026

    January 19, 2026
    • About
    • Tech Guest Post
    • Contact
    • Privacy Policy
    • Sitemap
    © 2026 About Chrome Books. All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.