• 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

How To Add A Location To The PATH Variable In Linux

Bhagwad Park

Published on: November 4, 2019

Categories: VPS Hosting 0

When you execute a command in Linux, the Operating System needs to know where to find it. This isn’t unusual since even the Windows CLI has the same requirement. In Windows, the list of locations where the OS searches from the command is specified by the “ENVIRONMENT” variable. In Linux, this is called the “PATH” variable instead.

There is one difference though, is that Windows automatically searches the current directory for the command, whereas Linux does not. In this article, I’ll show you how to permanently add a location to Linux’s PATH variable via a simple example.

Test Script in Local Directory

To demonstrate this, I create a test script that simply prints “Hello World” to the screen. After creating the script, I gave it the appropriate “755” permissions etc, so I won’t cover that here. The problem arises, when I try and execute the script like this:

Command Not Found in Linux

As you can see, the “testscript” file is sitting right in my local directory, but I’m still getting a “command not found” error when I try and run it. This is because I haven’t told Linux to specifically search my current local directory for the command. I can do this by typing this:

$ /.testscript

And then I get the expected result:

Need to Add the Current Folder

This time, the command executes and prints like I want it to. If you want to be able to execute scripts in the local directory without the additional hassle of typing “./”, you need to add the dot (.) to the PATH variable.

Why Isn’t the Dot (.) Included by Default?

A quick note as to why Linux behaves in this strange manner. It’s for security reasons. The danger is that someone could create a new version of a common command like “ls” and put it in your local directory. And if you just use “ls”, there is a danger that the malicious version will be used instead of the system default. For this reason, we’re going to add the current directory to the end of the PATH variable instead of the beginning. This way, system commands will be executed first.

Editing ~/.bash_profile

The PATH variable is located in ~/.bash_profile. To edit it, we’ll be using the native editor “vi”. I’d earlier written a tutorial on getting started with vi, so you can read that if you need to brush up quickly. We edit the file by typing:

vi ~/.bash_profile

Inside, you’ll see one of the lines starting with “PATH”. What we want, is to add the following to the end of the line:

:.

Like this:

Add Dot to the Path Variable

Save your changes and exit. Now the PATH variable will also search the current directory if the command isn’t found in any of the earlier locations. As seen above, this is for security reasons.

Unfortunately, your command still won’t work because the changes haven’t taken effect yet. To force the changes to go through, run the following:

source ~/.bash_profile

And now, the command works as expected:

Reload Bash and the Path is Now Included

Replacing “.” With Your Directory

This article was to show you how to add any location to the PATH variable. To do this, simply replace the current directory represented by a dot (.) with your fully qualified path. Reload the bash profile as shown above, and you’re done!

Of course, another approach is to simply move your custom commands to one of the existing locations in the PATH variable. You can see above, that two default locations are:

$HOME/.local/bin
$HOME/bin

Just move your custom scripts over to one of these locations and you can run them from the command line without needing to add anything to your PATH variables!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Echo vs Printf in Bash: What’s the Difference?

Echo and printf can both be used in bash for outputting text. However, echo is for quick output, whereas printf gives you more power.

Symbolic Links vs Hard Links in Linux

Linux offers various methods for referencing files and directories through other files and directories, without creating copies of the original. If you have color coding enabled in your bash terminal, you might have seen some folders full of files of a different color from regular files. There’s a good chance that these are all symbolic […]

How to Use Git Rebase Interactive to Manage Commits

As a project progresses, commits can get messy. The git rebase interactive feature allows you to keep a clean commit history.

Bash Conditional Expressions: [[ vs [ vs test

In bash scripts, we use conditional statements frequently. Whether it’s in an “if fi” logic block or within a “while” or “do” loop, we evaluate statements all the time to determine whether they’re true or false, and perform various actions based on the result. True to form, there are multiple ways to do this, and […]

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