Mac 使用 homebrew 安装 git 为啥无法替换系统自带的 git?

2014-11-21 15:48:06 +08:00
 turandot
尝试了各种方法无果,设置如下:

1./etc/paths:
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin

2.~/.bash_profile和~/.profile都留空 [之前尝试这两个文件加入环境变量无果]

3.echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

4.git --version
git version 1.9.3 (Apple Git-50)

还是自带的版本,brew安装的2.1.3未生效
9320 次点击
所在节点    macOS
18 条回复
hzlez
2014-11-21 15:49:24 +08:00
$ which git
/usr/local/bin/git

你brew install的git在不在/usr/local/bin中呢。
turandot
2014-11-21 15:54:12 +08:00
@hzlez
##我brew install 的git在/usr/bin/中。
turandot
2014-11-21 15:57:25 +08:00
@hzlez

➜ ~ brew list
git openssl wget
➜ ~ which openssl
/usr/bin/openssl
➜ ~ which wget
/usr/local/bin/wget
➜ ~ which git
/usr/bin/git

这是啥情况?为毛git和openssl在/usr/bin/但是wget在/usr/local/bin/?
ooxxcc
2014-11-21 16:02:48 +08:00
brew info git呢

你有没有brew link git
ooxxcc
2014-11-21 16:03:07 +08:00
另外看一下/usr/local/sbin/git存在不存在
turandot
2014-11-21 16:10:59 +08:00
@ooxxcc
➜ ~ brew info git
git: stable 2.1.3 (bottled), HEAD
http://git-scm.com
/usr/local/Cellar/git/2.1.3 (1342 files, 32M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/git.rb
==> Dependencies
Optional: pcre ✘, gettext ✘
==> Options
--with-blk-sha1
Compile with the block-optimized SHA1 implementation
--with-brewed-curl
Use Homebrew's version of cURL library
--with-brewed-openssl
Build with Homebrew OpenSSL instead of the system version
--with-brewed-svn
Use Homebrew's version of SVN
--with-gettext
Build with gettext support
--with-pcre
Build with pcre support
--with-persistent-https
Build git-remote-persistent-https from "contrib" directory
--without-completions
Disable bash/zsh completions from "contrib" directory
--HEAD
install HEAD version
==> Caveats
The OS X keychain credential helper has been installed to:
/usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
/usr/local/share/git-core/contrib

Bash completion has been installed to:
/usr/local/etc/bash_completion.d

zsh completion has been installed to:
/usr/local/share/zsh/site-functions

————————————————————————我是分割线————————————————————————————————————

➜ ~ /usr/local/sbin/git
zsh: no such file or directory: /usr/local/sbin/git

————————————————————————我是分割线————————————————————————————————————

没有brew link git,想的是设置好环境变量后通过brew install的都可以覆盖系统自带的
goofansu
2014-11-21 16:11:40 +08:00
.bash_profile里要加一句话的
turandot
2014-11-21 16:14:43 +08:00
@goofansu
是echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile吗?
每次brew update后brew doctor都会提示,设置似乎只对当前生效,每次update后都要再来一遍...
turandot
2014-11-21 16:19:40 +08:00
奇了怪了,reopen一下iterm,没有动任何设置,居然又发生了变化:
➜ ~ cat /etc/paths
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~ git --version
git version 1.9.3 (Apple Git-50)

echo $PATH的结果和之前不一样了
turandot
2014-11-21 16:35:49 +08:00
#update

好像是因为ohmyzsh的配置文件也设置了环境变量...
jsfaint
2014-11-21 16:38:00 +08:00
楼主你用的是zsh,PATH修改应该在.zshrc里面吧
ooxxcc
2014-11-21 16:39:26 +08:00
@turandot 你不link的话/usr/local/bin根本不会有git,你怎么设置PATH都没用啊

除非你把 /usr/local/Cellar/git/2.1.3 添加到PATH变量

另外你用zsh调什么.bash_profile

槽点太多……
ooxxcc
2014-11-21 16:39:50 +08:00
楼下可以散了
canautumn
2014-11-21 16:40:17 +08:00
把环境变量加到.zshrc里,不要加到.bash_profile里
turandot
2014-11-21 17:02:12 +08:00
@ooxxcc
@canautumn
哈哈,惭愧惭愧...,之前一直用bash...
修改.zshrc搞掂了
kqz901002
2014-11-24 14:16:00 +08:00
@turandot 修改.zshrc
kqz901002
2014-11-24 14:16:48 +08:00
@turandot = = 两天前de 帖子。。。。
turandot
2014-11-24 16:26:14 +08:00
@kqz901002 嗯嗯,已经可以愉快的玩耍了,anyway,还是thx了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/148303

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX