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

    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.

    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.

    Best of AI

    Imagen AI: The Best Photo Editing AI In 2026

    April 21, 2026

    Alphafold AI from Google Deepmind 2026

    April 21, 2026

    Agentic AI Pindrop Anonybit: The Future of Secure Identity Verification

    April 17, 2026

    Google Bard Statistics And User Data 2026

    April 10, 2026

    Azure OpenAI Explained

    April 10, 2026
    Trending Stats

    ChromeOS Accessibility Feature Usage Statistics 2026

    April 28, 2026

    Chromebook Resale Value Depreciation Statistics 2026

    April 27, 2026

    ChromeOS App Ecosystem Growth Statistics 2026

    April 25, 2026

    Chromebook vs Tablet Usage In Education Statistics 2026

    April 23, 2026

    ChromeOS Update Frequency Statistics 2026

    April 22, 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.