V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
turandot
V2EX  ›  macOS

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

  •  
  •   turandot · 2014-11-21 15:48:06 +08:00 · 9374 次点击
    这是一个创建于 3657 天前的主题,其中的信息可能已经有所发展或是发生改变。
    尝试了各种方法无果,设置如下:

    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未生效
    18 条回复    2014-11-24 16:26:14 +08:00
    hzlez
        1
    hzlez  
       2014-11-21 15:49:24 +08:00
    $ which git
    /usr/local/bin/git

    你brew install的git在不在/usr/local/bin中呢。
    turandot
        2
    turandot  
    OP
       2014-11-21 15:54:12 +08:00
    @hzlez
    ##我brew install 的git在/usr/bin/中。
    turandot
        3
    turandot  
    OP
       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
        4
    ooxxcc  
       2014-11-21 16:02:48 +08:00
    brew info git呢

    你有没有brew link git
    ooxxcc
        5
    ooxxcc  
       2014-11-21 16:03:07 +08:00
    另外看一下/usr/local/sbin/git存在不存在
    turandot
        6
    turandot  
    OP
       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
        7
    goofansu  
       2014-11-21 16:11:40 +08:00 via iPad
    .bash_profile里要加一句话的
    turandot
        8
    turandot  
    OP
       2014-11-21 16:14:43 +08:00
    @goofansu
    是echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile吗?
    每次brew update后brew doctor都会提示,设置似乎只对当前生效,每次update后都要再来一遍...
    turandot
        9
    turandot  
    OP
       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
        10
    turandot  
    OP
       2014-11-21 16:35:49 +08:00
    #update

    好像是因为ohmyzsh的配置文件也设置了环境变量...
    jsfaint
        11
    jsfaint  
       2014-11-21 16:38:00 +08:00
    楼主你用的是zsh,PATH修改应该在.zshrc里面吧
    ooxxcc
        12
    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
        13
    ooxxcc  
       2014-11-21 16:39:50 +08:00
    楼下可以散了
    canautumn
        14
    canautumn  
       2014-11-21 16:40:17 +08:00
    把环境变量加到.zshrc里,不要加到.bash_profile里
    turandot
        15
    turandot  
    OP
       2014-11-21 17:02:12 +08:00
    @ooxxcc
    @canautumn
    哈哈,惭愧惭愧...,之前一直用bash...
    修改.zshrc搞掂了
    kqz901002
        16
    kqz901002  
       2014-11-24 14:16:00 +08:00
    @turandot 修改.zshrc
    kqz901002
        17
    kqz901002  
       2014-11-24 14:16:48 +08:00
    @turandot = = 两天前de 帖子。。。。
    turandot
        18
    turandot  
    OP
       2014-11-24 16:26:14 +08:00
    @kqz901002 嗯嗯,已经可以愉快的玩耍了,anyway,还是thx了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1308 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:50 · PVG 01:50 · LAX 09:50 · JFK 12:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.