Learn How to Set Your $PATH Variables Permanently in Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Marin Todorov

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

16 Responses

  1. Matt says:

    Frustrating, because there’s very incomplete information here. “In this tutorial you are going to learn how to set $PATH variable globally and locally.” Really? I’m going to set the path for the whole world? What do you -really- mean by globally? (For all users, I’m assuming)

    “First, let’s see your current $PATH’s value. Open a terminal and issue the following command: echo $PATH
    Why can’t I just type “$PATH“? Seems to do the same thing.

    I don’t see anything about path in my .bashrc file.

    # cat .bashrc | grep PATH 

    “$ export PATH=$PATH:/path/to/newdir”

    What if I make an unnoticed typo; how do I fix that?

  2. Ashwini P B says:

    Whenever I open the terminal in Linux, I get a new blank page, but to continue from where I had stopped, what should I do?

  3. Anu Shibin says:

    Hi Marin,

    This works. But I need this to work automatically every-time my machine boots up. Now I have to run the source ~/.profile every time I restart. Is there any way to do this automatically?

  4. Kushagra says:

    I have vxargs.py script in directory “/home/csgrads/kumar392/RESILIO“. However when I try to add the directory “/home/csgrads/kumar392/RESILIO” to the path it gives an error – Bad : modifier in $ (/).

    I used the command mentioned by you, i.e. export PATH=$PATH:/home/csgrads/kumar392/RESILIO.

    Can you please help.

  5. kevin says:

    what about the process that running in crontab, which files should I add “export PATH” ??

  6. Tomatreides says:

    Great post!

    You can also use /etc/environment to set PATH environment variable, but it does not support variable expansion.

    • Erik says:

      Thank you “tomatreides” for this comment. It just solved a problem I have had more more than one week.

      We had this odd problem on a CentOS 7.3.1611 box where we installed Java 1.7.0_80, not upgraded or updated Java but a fresh install. What we noticed was that the PATH seems to have been ruined by something, but we could not figure out by what or how. You just solved that!

      Our theory is that the Java installation wrongfully puts its stuff in the “/etc/environment”-file and that then completely ruins the PATH variable since the PATH then contain “$PATH” and “$JAVA_HOME” instead of its expanded content.

      The fix is to move the Java related content from the “environment” file into a new file in the folder: “/etc/profile.d/”. Using the files “/etc/profile” or “/etc/bashrc” or any other system wide file is not recommended. Using e.g. “~/.bash_profile” or “~/.bashrc” or any other user specific file is also not recommended. The files in “/etc/profile.d/” are also not affected if you update the OS. So this is imho where this type of things should have been done in the first place (Oracle, are you listening?).

      Maybe there is a better way to solve this, but this works for us. I hope this helps anyone else who have the same problem. If you want to know more please reply to this comment and I will be more than happy to help you.

  7. Amit says:

    Nice article .. If we need to use java on ubuntu then what are the parameters we should use? or on which file.
    Any help will be appreciated!!

  8. sahil says:

    thanks its a very informative ..

  9. David says:

    Great post and great blog!!!
    In my PATH I have some variables repeated, e.g., /usr/local/bin

    I’ve never had issues with that, so I think that it should not be so important to have duplicates, am I wrong?

    • Kyle says:

      The path is resolved with the first match. If you have identically named executables then the specific order of the paths are important and you might find unexpected behavior when there are duplicate or out of sequence entries.

  10. Rodolfo says:

    you should include fishshell

Got something to say? Join the discussion.

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.