[英]How to properly setup my git $PATH on my mac (I did, but need to understand how it really works)?
I installed GIT from the site on my mac, but git --version gave me the old installation (I guess xcode installation). 我在我的mac上从网站安装了GIT,但是git --version给了我旧的安装(我猜xcode安装)。 So I solved doing this:
所以我解决了这个问题:
write: 写:
export PATH=/usr/local/bin:$PATH export PATH = / usr / local / bin:$ PATH
restart the terminal 重启终端
Though, I think there's something in my configuration I could better setup. 虽然,我认为我的配置中有一些东西可以更好地设置。
My current echo $PATH 我目前的回音$ PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin 在/ usr / local / bin目录:在/ usr / bin中:/ bin中:/ usr / sbin目录:/ sbin目录:在/ usr / local / bin目录:在/ usr /本地/ git的/ bin中
So IT WORKS, but it's quite a mess, since I've got 2 /usr/local/bin AND an /usr/local/git/bin 所以它工作,但它很乱,因为我有2 / usr / local / bin和/ usr / local / git / bin
Also, I cannot understand WHY now it works, since /usr/local/bin only contains bbedit commands: 此外,我无法理解为什么它现在可以工作,因为/ usr / local / bin只包含bbedit命令:
I do not know very well all the path-config files and the real order they are read. 我不太清楚所有的路径配置文件和它们被读取的真实顺序。 I only know a few unix commands.. My current files in ~/ are:
我只知道一些unix命令..我当前的文件〜/是:
~/.profile: 〜/ .profile文件:
if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi
~/bashrc: 〜/ .bashrc中:
. ~/bin/dotfiles/bashrc
then in . 然后在。 ~/bin/dotfiles/bashrc
〜/斌/点文件/ .bashrc中
. ~/bin/dotfiles/bash/env
. ~/bin/dotfiles/bash/config
. ~/bin/dotfiles/bash/aliases
and in . 并在。 ~/bin/dotfiles/bash/env:
〜/斌/点文件/庆典/ ENV:
export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
. 。 ~/bin/dotfiles/bash/config is just empty
〜/ bin / dotfiles / bash / config只是空的
and . 和。 ~/bin/dotfiles/bash/aliases contains some alias commad.
〜/ bin / dotfiles / bash / aliases包含一些别名commad。
Anyway, it SHOULD have read ~/bin/dotfiles/bash/env, but it doesn't. 无论如何,它应该读取〜/ bin / dotfiles / bash / env,但事实并非如此。 Or it reads it only after /etc/paths
或者只在/ etc / paths之后读取它
~/.bash_profile is read first instead. 首先读取〜/ .bash_profile。
My current /etc/paths content: 我当前的/ etc / paths内容:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
Can anyone explain me the these mechanics? 谁能解释一下这些机制呢? :P Or Maybe I should post this question to some Unix group?
:P或者也许我应该把这个问题发给一些Unix组?
When you type any command on a *NIX shell, the shell tries to resolve that command using the $PATH
. 当您在* NIX shell上键入任何命令时,shell会尝试使用
$PATH
解析该命令。 Say your path is /usr/bin:/usr/local/bin
, then this happens: 说你的路径是
/usr/bin:/usr/local/bin
,然后发生这种情况:
$ foo
- Does /usr/bin/foo exist? No.
- Does /usr/local/bin/foo exist? No.
- Does foo exist in the current working directory?
In other words, it looks at each $PATH
element in turn and tries to find the executable you asked for there. 换句话说,它依次查看每个
$PATH
元素并尝试查找您在那里请求的可执行文件。 This is the reason the typical configure
- make
- make install
procedure starts with a ./configure
, to make explicit that you want to run the configure
executable in the current directory , not some system-wide command. 这就是典型的
configure
- make
- make install
过程以./configure
开头的原因,以明确表示您要在当前目录中运行configure
可执行文件,而不是某些系统范围的命令。
To figure out which foo
it's actually choosing in the end, run: 要弄清楚它最终选择了哪个
foo
,请运行:
$ which foo
You can run any command explicitly by providing its full path: 您可以通过提供其完整路径来显式运行任何命令:
$ /usr/local/bin/foo # overrides /usr/bin/foo, should it exist
The export PATH=...:$PATH
directive in your initialization scripts is simply prepending certain paths to your path, allowing you to override the precedence in which order commands are resolved. 初始化脚本中的
export PATH=...:$PATH
指令只是在路径上添加某些路径,允许您覆盖解析顺序命令的优先级。 It's not ideal that /usr/local/bin
is in there twice, but it's not really a problem either. /usr/local/bin
在那里两次并不理想,但它也不是真正的问题。 You should take care not to let your path grow too long, since that may result in a lot of lookups for every command and may screw with your head, too. 你应该注意不要让你的路径长得太长,因为这可能会导致对每个命令进行大量的查找,并且可能会对你的头部产生影响。
有关bash配置文件的加载顺序的全面演练,请参阅此内容 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.