Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
40.15k stars 9.41k forks source link

Homebrew not finding newer git from $PATH #6274

Closed joseph-long closed 5 years ago

joseph-long commented 5 years ago

What you were trying to do (and why)

brew update a new install of LinuxBrew to /extra/josephlong/.linuxbrew.

What happened (include command output)

Despite the existence of a newer git on $PATH:

17:30:23 login2:~ josephlong$ git --version
git version 2.9.5
17:30:25 login2:~ josephlong$ which git
~/.local/bin/git

Homebrew appears to use system git, which is much older:

$ brew config
[...]
Git: 1.7.1 => /usr/bin/git
[...]

which results in the following errors:

Command output

  $ brew update
==> Installing dependencies for curl: pkg-config and openssl
==> Installing curl dependency: pkg-config
error: unknown option `local'
usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    -f, --file      use given config file

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color     find the color configured: [default]
    --get-colorbool 
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte

Error: Failure while executing; `git config --local --replace-all homebrew.private false` exited with 129.
==> Installing dependencies for git: patchelf, zlib, binutils, linux-headers, glibc, m4, gmp, mpfr, libmpc, isl@0.18, gcc, pkg-config, gpatch, ncurses, gettext, bzip2, pcre2, openssl, curl, libbsd and expat
==> Installing git dependency: patchelf
error: unknown option `local'
usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    -f, --file      use given config file

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color     find the color configured: [default]
    --get-colorbool 
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte

Error: Failure while executing; `git config --local --replace-all homebrew.private false` exited with 129.
error: unknown option `list'
usage: git tag [-a|-s|-u ] [-f] [-m |-F ]  []
   or: git tag -d ...
   or: git tag -l [-n[]] []
   or: git tag -v ...

    -l                    list tag names
    -n[]               print  lines of each tag message
    -d                    delete tags
    -v                    verify tags

Tag creation options
    -a                    annotated tag, needs a message
    -m               message for the tag
    -F              message in a file
    -s                    annotated and GPG-signed tag
    -u            use another key to sign the tag
    -f, --force           replace the tag if exists

Tag listing options
    --contains    print only tags that contain the commit

error: unknown option `list'
usage: git tag [-a|-s|-u ] [-f] [-m |-F ]  []
   or: git tag -d ...
   or: git tag -l [-n[]] []
   or: git tag -v ...

    -l                    list tag names
    -n[]               print  lines of each tag message
    -d                    delete tags
    -v                    verify tags

Tag creation options
    -a                    annotated tag, needs a message
    -m               message for the tag
    -F              message in a file
    -s                    annotated and GPG-signed tag
    -u            use another key to sign the tag
    -f, --force           replace the tag if exists

Tag listing options
    --contains    print only tags that contain the commit

    ==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics

error: unknown option `local'
usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    -f, --file      use given config file

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color     find the color configured: [default]
    --get-colorbool 
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte

Error: Failure while executing; `git config --local --replace-all homebrew.analyticsmessage true` exited with 129.

  

What you expected to happen

I expected brew update to complete without errors.

Step-by-step reproduction instructions (by running brew commands)

$ cd /extra/$USER   # non-standard install prefix
$ git clone https://github.com/Homebrew/brew .linuxbrew/Homebrew
$ mkdir .linuxbrew/bin
$ ln -s ../Homebrew/bin/brew .linuxbrew/bin
$ eval $(/extra/josephlong/.linuxbrew/bin/brew shellenv)
$ brew update

brew doctor

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: An outdated version (1.7.1) of Git was detected in your PATH.
Git 2.7.0 or newer is required for Homebrew.
Please upgrade:
  brew install git

Warning: Your Homebrew's prefix is not /home/linuxbrew/.linuxbrew.
Some of Homebrew's bottles (binary packages) can only be used with the default
prefix (/home/linuxbrew/.linuxbrew).
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience, as you are running this unsupported configuration.

brew config

HOMEBREW_VERSION: >=1.7.1 (shallow or no git repository)
ORIGIN: https://github.com/Homebrew/brew
HEAD: 6418230f8fc86093f96f4156a2cdcabfd55f03f7
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/linuxbrew-core
Core tap HEAD: 42e132d75e8ee9ddf01e975ba28dbb0f3f791686
Core tap last commit: 3 hours ago
HOMEBREW_PREFIX: /extra/josephlong/.linuxbrew
HOMEBREW_CELLAR: /extra/josephlong/.linuxbrew/Cellar
HOMEBREW_CACHE: /home/u32/josephlong/.cache/Homebrew
HOMEBREW_LOGS: /home/u32/josephlong/.cache/Homebrew/Logs
HOMEBREW_REPOSITORY: /extra/josephlong/.linuxbrew/Homebrew
HOMEBREW_NO_ANALYTICS_THIS_RUN: 1
HOMEBREW_SYSTEM_CURL_TOO_OLD: 1
HOMEBREW_VISUAL: nano
CPU: 28-core 64-bit haswell
Homebrew Ruby: 2.3.7 => /extra/josephlong/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/bin/ruby
Clang: 3.4 build 34
Git: 1.7.1 => /usr/bin/git
Curl: 7.19.7 => /usr/bin/curl
Kernel: Linux 2.6.32-754.12.1.el6.x86_64 x86_64 GNU/Linux
OS: CentOS release 6.10 (Final) (Final)
Host glibc: 2.12
/usr/bin/gcc: 4.4.7
glibc: N/A
gcc: N/A
xorg: N/A
sjackman commented 5 years ago

Unfortunately, I use Linuxbrew to try and save myself from the outdated software on my University's HPC cluster... they won't let me upgrade them to a newer CentOS 🙃

I created Linuxbrew for this reason, so you're in good company.

sjackman commented 5 years ago

Try these (untested) alternative alternative (alternative²) installation instructions using curl rather than git to install Homebrew:

mkdir -p /home/linuxbrew/.linuxbrew/bin
curl -L https://github.com/Homebrew/brew/archive/2.1.6.tar.gz | tar zx -C /home/linuxbrew/.linuxbrew/Homebrew
ln -s ../Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
sjackman commented 5 years ago

A couple of options to try to use your local ~/.local/bin/git executable. First, try export HOMEBREW_NO_ENV_FILTERING=1 to use your PATH rather than the default /usr/bin:/bin. Second, you can export HOMEBREW_DEVELOPER=1 HOMEBREW_GIT_PATH=$HOME/.local/bin/git.

sjackman commented 5 years ago

https://github.com/Homebrew/brew/blob/6418230f8fc86093f96f4156a2cdcabfd55f03f7/Library/Homebrew/brew.sh#L201-L204

sjackman commented 5 years ago

Once you get it working, I'd be most happy to review a PR that makes the installation smoother on older distributions. Here's a wiki with installation instructions on for CentOS 6. Feel free to edit it: https://github.com/Linuxbrew/brew/wiki/CentOS6

joseph-long commented 5 years ago

export HOMEBREW_NO_ENV_FILTERING=1 might have done the trick! I'm certainly getting further along with brew update.

joseph-long commented 5 years ago

I tried the curl instructions just to see if they worked (since that would be easier to document than building one's own git), but unfortunately brew update starts by converting the checkout to a shallow clone. I tried brew install git but it just installs portable ruby and then it too tries to convert the checkout to a git repo.

joseph-long commented 5 years ago

Written up at https://joseph-long.com/writing/linuxbrew-with-ancient-git/ for posterity, as the wiki page you linked is archived. If there's another good place to put it, I can copy it over!

sjackman commented 5 years ago

Nice write up! I've tweeted your article here: https://twitter.com/linuxbrew/status/1146457021174054918 Are you on Twitter? I couldn't find your handle. Get thee on Twitter! If only so other Science tweeps can tag you in posts.

Cutting edge research, eight year old operating systems. Go figure.

😂 This issue still mystifies me. Dealing with a ten year old operating system consumes so much time. It's absolutely insane. Docker and Singularity should help a lot. My site won't use Docker because of security concerns, but they're excited about Singularity.

sjackman commented 5 years ago

an enterprising graduate student

That's me! Also, I graduated last month! I have a photo of me wearing a silly hat to prove it. 🎓 Would you mind linking to my web site? https://sjackman.ca

sjackman commented 5 years ago

the wiki page you linked is archived

Hmm. Yes, I forgot about that. Do you have the time and inclination to submit a PR to improve the installation of Homebrew on older distributions? This would largely amount to detecting when git is too old, and either failing with a (hopefully helpful) error message, or better, taking an alternative installation route by default. If so, I'm happy to point you to the right section of code to get started hacking.

MikeMcQuaid commented 5 years ago

If so, I'm happy to point you to the right section of code to get started hacking.

Here's some of the relevant code:

https://github.com/Homebrew/brew/blob/895467ad9f57a9245c36def26abca729f2559fbb/Library/Homebrew/brew.sh#L114-L128 https://github.com/Homebrew/brew/blob/895467ad9f57a9245c36def26abca729f2559fbb/Library/Homebrew/brew.sh#L151-L159 https://github.com/Homebrew/brew/blob/895467ad9f57a9245c36def26abca729f2559fbb/Library/Homebrew/brew.sh#L161-L168

It seems some of this should be happening already.

joseph-long commented 5 years ago

In the command output above, you can see brew following the "force brewed git" (and curl) path, but other parts of Homebrew are supplying arguments to git that are too new, and the attempt to install its own git fails.

I'm not sure if I should go through and make those invocations of git backwards compatible all the way back to 1.7.1... ideally there'd be a "portable git" like the portable ruby homebrew installs, but that may be more effort than it's worth for such an old system.

sjackman commented 5 years ago

It's only really brew update and some git config stuff that requires git. Much of that can be deferred until we have a working version of brewed git installed. The fix as I see it would be to detect when the system version of git is missing or too old (when HOMEBREW_FORCE_BREWED_CURL is set), and if the brewed git is not yet installed, skip running git. For example, don't auto-update until the brewed git is installed. Does that make sense?