tags:

views:

536

answers:

4

I tried to include the following unsuccessfully to my ~/.profile:

export PATH='$HOME/opt/git/bin'

It seems not to work because $git gives me nothing. I am trying to install Git.

I have also tried commands here.

+1  A: 

This should have worked.

Where does $HOME point to?

Make sure that $HOME/opt/git/bin actually contains an executable file called git.

DasBoot
To add something to the path I think is not needed that the file actually exists
Eduardo
$HOME points to /home/mas.This what $HOME/opt/git/bin contains: http://dl.getdropbox.com/u/175564/opt-git-bin.png
Masi
+2  A: 

Hi,

You need to delete the ' ', try this

export PATH=$HOME/opt/git/bin

And to do not overwrite your whole path try this:

export PATH=$PATH:$HOME/opt/git/bin
Eduardo
In most cases, you'd want to prefix user specific paths, not suffix them, so that they take priority.
Matthew Scharley
No change, when I tested your code in ~/.profile.
Masi
+6  A: 

You'll want to be careful with that command. It will override your $PATH.

You might need to put it in ~/.bash_profile and change it to this:

export PATH="$HOME/opt/git/bin:$PATH"
sirlancelot
Your code works in ~/.profile after I restarted terminal. Thank you!
Masi
Glad it worked! I voted up your question.
sirlancelot
+3  A: 

As SirLancelot pointed out, you reset your path rather than augmenting it. You also used single quotes instead of double quotes, so the value set was exactly the string shown, rather than containing the expanded value of $HOME. As noted, the correct solution to that is to use:

export PATH="$PATH:$HOME/opt/git/bin"

Or you can reverse the order:

export PATH="$HOME/opt/git/bin:$PATH"

However, all that does is ensure that when you type git, the executable will be found.

Your question also mentions using $git; you would have to set that variable, perhaps using:

export git=$(which git)

Having said that, I don't see an advantage to using $git when git is on your PATH; it is one extra character to type (and a shifted-digit too). If you want to continue using $git, you probably shouldn't add $HOME/opt/git/bin to PATH. Its presence slows down unsuccessful command searches, and if you always access git via $git (which would now have to be set using: export git=$HOME/opt/git/bin/git) there is no benefit to having the git bin directory on your PATH.


Masi commented about order being meaningless, and Douglas Leeder responded:

The order isn't meaningless - it's the order [in which directories are] searched. However, git isn't in any of your other search directories, and there shouldn't be any overlap between the commands in the git bin directory and any others, so the order won't make any difference in this case.

That's basically accurate, but I'll spin it a bit. When a command is searched for, the system looks for the program by looking for it in each directory in PATH until it finds it. So, when it looks for ls, for example, with the git bin directory at the front of the PATH, the shells will look for $HOME/opt/git/bin/ls and not find it, and pass on to other directories in your PATH, eventually finding it in /usr/bin/ls or /bin/ls. Some shells cache the location where a program is found; other's don't. So, it can make sense to keep /bin and /usr/bin near the front of your PATH, to speed up access to the standard utilities. I always keep $HOME/bin at the front of my PATH; that way, I can override anything with my own version - and I do that for some commands.

Also, on my main work machine, the /usr/local/bin directory isn't under my control. I don't trust it, therefore, and I make sure it is right at the end of my PATH, so the antique GCC in it is not the one I use, for example. [Hmmm; they've updated it to 3.4.6; it used to be 2.95 or thereabouts; still, I use 4.3.3.]

One more suggestion for you. Consider creating a symlink in your $HOME/bin (assuming you have one and it is on your PATH) that points to the install location of git. This means you don't add an extra directory to PATH (so things work marginally faster) but you do get to use the version of git you choose to use.

ln -s $HOME/opt/git/bin/git $HOME/bin/git
Jonathan Leffler
Thank you! I did not know that the order is meaningless.
Masi
The order isn't meaningless - it's the order that searched - however git isn't is any of your other search directories, and there shouldn't be any overlap between the commands in the git bin directory and any others so the order won't make any difference in this case.
Douglas Leeder