• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

Understanding What The Linux PATH Variable Is And How To Add To It

CJ Saathoff

Published on: June 26, 2024

Categories: Linux Command Line 0

Have you ever wondered how Linux and other Unix-like operating systems know where programs are located when you try and run a command? The path variable is responsible for this, it tells the operating system where to search for executable files. Contained in the path variable is a list of directories that are searched though in order till the file with the same name is found and run.

In this post we will explore related background, how to check your path, how the path works, and how to add more file paths to your path. 

Table of Contents
  • What Is A Variable?
  • What Are Environmental Variables?
    • To Check An Environment Variable.
  • What is the PATH variable?
  • Understanding The Importance Of Order Within PATH
  • Managing PATH
    • Adding To PATH
  • Conclusion

What Is A Variable?

A variable let’s take something like $file to represent the path to a file. User variables can be set by scrips or from the command prompt directly.

What Are Environmental Variables?

Unlike shell variables, environment variables are system variables related to the environment you’re working from. Here are some examples of system environment variables:

  • PATH: Specifies the directories where the system looks for executable files.
  • HOME: Points to the current user’s home directory.
  • USER: Contains the username of the current user.
  • SHELL: Specifies the default shell for the user.
  • PWD: Represents the present working directory.
  • LANG: Sets the default system language.
  • EDITOR: Defines your preferred text editor

To Check An Environment Variable.

To check one environment variable you can use the following syntax:

echo $VARIABLE

To see all of them run one of the following commands:

printenv
env

What is the PATH variable?

The PATH variable contains the PATHs that the system for look for commands/executable files. So when you run a command for example the ls command, it finds an executable file at /usr/bin/ls and then runs it.

Understanding The Importance Of Order Within PATH

Order matters when it comes to path, say your path points to these three locations (I expect your path will be longer)

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

The system will check the first location and do one of two things.

  1. Run the file named the command
  2. Or move on to the next location

It will loop through this until a command is run or there are no places left to check, if that happens you will get a command not found.

Managing PATH

The total path will be put together from a few different locations, ones managed by the system administrator and others a user can edit.

Files the system administrator manage

  1. /etc/environment: This file can be used to set system-wide environment variables like PATH.
  2. /etc/profile: This file is executed for login shells and can set system-wide environment variables.
  3. /etc/profile.d/: This directory contains scripts that are sourced by /etc/profile and can be used to set additional environment variables, including PATH.
  4. /etc/bash.bashrc or /etc/bashrc: These files are system-wide bashrc files and can also be used to set system-wide PATH variables.

Files users can modify there path from

  1. ~/.bash_profile, ~/.bash_login, or ~/.profile: These files are specific to individual users and are executed for login shells. Users can set their own PATH variable in these files.
  2. ~/.bashrc: This file is executed for interactive non-login shells and can be used by users to set their own PATH variable.

Adding To PATH

When editing the path variable it’s important to append it to the existing path to avoid users no longer being able to run applications.

This can be done by adding the following line to the desired file from above, let’s use ~/.bashrc.

Open the file in your preferred text editor.

nano ~/.bashrc

Add the following line.

# Set path
export PATH=$PATH:~/.local/bin

To apply this you will either need to open a new terminal or run the following command.

source ~/.bashrc

This example adds the path ~/.local/bin which is Python, node, and ruby applications get installed when run by a user among other things.

Conclusion

In this blog post, we have discussed how the Linux path variable contains file paths to directories that contain the executable files that are run when running commands. Meaning if you would like to run an executable file without the full path you will want a make sure the location is listed in the path. This applies to custom scripts, installed Python applications, etc. Be sure to keep in mind that order matters, and you should be good to go. 

CJ Saathoff

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.

Related Posts

Differentiating the df vs du Commands in Linux

Both df and du are Linux commands for estimating disk usage, but they differ in their focus. Df stands for “disk free”, and du stands for disk usage. The first shows the amount of free space available on a volume, and the second shows the amount of space used by specific directories. Both commands have […]

Dealing with Cron Job Logs in Linux

Cron job logs keep track of which cron jobs run, and their details. This helps with troubleshooting and performance management.

How to Use set -e -o pipefail in Bash, and Why

While writing scripts in bash, it's important to be careful about error handling. That's what set -e -o pipefail does.

How to Prune Unused Images in Docker

In Docker, containers and images can build up over time, using up space and resources. Here's how to get rid of them.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA