changing an environment variable like PATH forever

37,294

Solution 1

make the setting persistent:

add this line: export PATH=/path/to/dir in your ~/.bashrc if using bash, or ~/.zshrc for zsh:

$ vim ~/.bashrc

export PATH=$PATH:/path/to/dir

:wq

or:

$ echo "export PATH=$PATH:/path/to/dir" >> ~/.bashrc

LATER EDIT!

Solution 2

Each time you execute a bash (non-login) shell instance, it reads and executes the .bashrc file in your home directory. Login shells, on the other hand, do that for .profile file, located in your home directory. You can find the difference between login and non-login shells by reading the bash manual.

In your case, open your ~/.bashrc and set there the variable that you want. For example:

PATH="/some/new/path:$PATH"

Save it, and reload it:

$ source ~/.bashrc

Share:
37,294

Related videos on Youtube

M0εiπ
Author by

M0εiπ

Updated on September 18, 2022

Comments

  • M0εiπ
    M0εiπ over 1 year

    Possible Duplicate:
    How do I set a user environment variable? (permanently, not session)

    To change the amount of PATH variable , I use : export PATH=...

    But when I close the terminal, the amount of PATH becomes what it was at first.

    I want to save the changes, so that the amount will be what I want after closing the terminal or logging out.

    How can I do this work?

    I use Fedora 17, kernel : 3.4.3

    • jw013
      jw013 almost 12 years
      another possible duplicate about setting environment variables
    • Jeff Schaller
      Jeff Schaller almost 7 years
      @Pierre.Vriens thank you for your edits/improvements! Something that I learned when starting to edit: realize that if you edit the text of a closed post (such as this one), it puts it into the ReOpen queue, so please continue to write good comments about what you changed, so that the reviewers know it was just typo-fixes and not an attempt to re-open the question. Thank you!
    • Pierre.Vriens
      Pierre.Vriens almost 7 years
      @JeffSchaller merci for the comment, will try to do as you suggested. However I might as well skip the closed ones (there are still tons of similar ones to be edited / improved). Not "my" personal preference, but at least it prevents the side-effect you mentioned.
    • Jeff Schaller
      Jeff Schaller almost 7 years
      de rien! I don't mean to slow your efforts to improve the site. If it was me, I might focus on highly-viewed and/or highly-voted entries (even if they were closed), to provide a better face for them. Again, it makes the reviewers job easy if you clearly indicate what you were doing -- then it's just a "keep closed" vote.
  • dkaragasidis
    dkaragasidis almost 12 years
    It's always a good idea to append values to an existing PATH variable.
  • Waqas
    Waqas almost 12 years
    you are right. i assumed that he knew how to set the path and the problem was only how to make it persistent.