Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am doing this:

$ which cabal
/usr/bin/cabal
$ export PATH=$PATH:$HOME/.cabal/bin
$ which cabal
/usr/bin/cabal

I expect to get /.cabal/bin/cabal for $ which cabal (this path exists) after this. But I don't even after re-opening the terminal. How come?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

The paths in $PATH are searched in order. This allows you to override a system default with:

export PATH=$HOME/bin:$PATH

$HOME/bin is now the first (highest priority) path. You did it the other way around, making it the last (lowest priority) path. When the shell goes looking, it uses the first match it finds.

In case it's not clear, this all works by concatenating strings. An analogy:

WORD=bar
WORD=foo$WORD

$WORD is now foobar. The : used with $PATH is literal, which you can see with echo $PATH.

share|improve this answer
    
and what do I do? –  Alex Jul 14 at 12:05
    
Use export PATH=$HOME/.cabal/bin:$PATH -- with $PATH after $HOME/.cabal/bin. In case it's not clear, this works by concatenating the old value of $PATH with some new value(s). Analogy: WORD=bar; WORD=foo$WORD -> $WORD is now foobar. WRT $PATH, don't forget the colon in between. –  goldilocks Jul 14 at 12:18
    
and how do I remove the one I've already added? –  Alex Jul 14 at 12:58
1  
If you did it on the command line, you can just exit the shell/terminal you're using -- export applies it to the current shell and all its children, not everything that's running. If you put it in .bash_profile or something, just change it and log in again. In any case, it's harmless to add the path at the beginning and leave it at the end as well. –  goldilocks Jul 14 at 13:10
1  
...the issue is that some graphical login systems ("display managers") don't source .bash_profile, but they do use .xsession -- so if you source ~/.bash_profile in ~/.xsession it will work. unix.stackexchange.com/questions/47359/what-is-xsession-for –  goldilocks Jul 14 at 14:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.