3

This question already has an answer here:

I have ruby and homebrew running for a while and I'm starting to play with Bash. I have encountered a problem with my PATH variable as echo'd:

/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin??n’export

As you can see, there is both redundancy and junk at the end int he form of illegal characters (causing a host of other issues). I can change the PATH with

export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin"

which does indeed return the desired PATH when echo'd:

/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

But I can't figure out for the life of me how to save the PATH so that it doesn't reset on reopening. I don't need to add paths. I just want to make this the new value of that variable. Please, how can I make this change permanent?

marked as duplicate by nohillside Jul 22 '15 at 7:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You can simply add your export PATH... line in your bash_profile file. This file is run every time you start terminal and will modify your PATH variable as you want. You can open/edit this from anywhere in terminal using

 open ~/.bash_profile

You probably also want to check that there are no conflicting export PATH... statements that overwrite each other or something.

  • Okay, I found this, and it did indeed work, so I'm all set on that front, but since that file was originally empty, where is the file that stored the original statement? Can the original or the default be edited in any way? I assume so because macports managed to do so which is what messed it up in the first pace. Or do we not do follow-up questions here? Either way, thank you for the response! – Tomm Jul 22 '15 at 4:27
  • Hmm sorry, that one is a little bit out of my depth, I did have a quick search but couldn't quite pin down where the default variables come from. I'll leave that for someone else. Also, it might be a good idea splitting it off into a separate question, its more likely to elicit more responses and makes it easier for people searching for the same question in the future. (I don't actually know what the official policy is on follow-ups though) – xyzen Jul 22 '15 at 4:42
  • Check .profile. – cubuspl42 Jul 22 '15 at 5:31
  • 1
    Or grep -r "export PATH" / ;) – cubuspl42 Jul 22 '15 at 5:32
  • @cubuspl42 is correct in that it may be set in your .profile. It can also be set (system wide) in /etc/profile or /etc/bashrc, though it isn't set there by default. There is also the file /etc/paths which contains a list of directories to include in $PATH, and the directory /etc/paths.d which includes further customisations. – forquare Jul 22 '15 at 6:12

Not the answer you're looking for? Browse other questions tagged .