Homebrew cannot find installed git and curl in the user directory

I’m trying to install linuxbrew for normal users. I have minimally installed Oracle Linux 7.7 and put in a user test without root rights. I have gradually compiled and installed all packages that Linuxbrew needs under user test. Now the problem is under user test, all libraries and packages like git are in / home / test / usr / {bin, lib, lib64, include etc.} but brew doesn’t know installed git or curl. Path in bashrc are correct so I think these are ENV:

[test@testing ~]$ which curl
~/usr/bin/curl

[test@testing ~]$ which git
~/usr/bin/git

[test@testing ~]$ env

 CPLUS_INCLUDE_PATH=/home/test/usr/include
    XDG_SESSION_ID=24
    HOSTNAME=testing
    SELINUX_ROLE_REQUESTED=
    TERM=xterm
    SHELL=/bin/bash
    HISTSIZE=1000
    SSH_CLIENT=192.168.0.234 64558 22
    SELINUX_USE_CURRENT_RANGE=
    SSH_TTY=/dev/pts/0
    USER=test
    LD_LIBRARY_PATH=/home/test/usr/lib:/home/test/usr/lib64
    PATH=/home/test/localperl/bin:/home/test/usr/bin:/home/test/usr/libexec:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/test/.local/bin:/home/test/bin
    C_INCLUDE_PATH=/home/test/usr/include
    PWD=/home/test
    LANG=en_US.UTF-8
    SELINUX_LEVEL_REQUESTED=
    HISTCONTROL=ignoredups
    SHLVL=1
    HOME=/home/test
    LOGNAME=test
    SSH_CONNECTION=192.168.0.234 64558 192.168.0.200 22
    PKG_CONFIG_PATH=/home/test/usr/lib/pkgconfig:/home/test/usr/lib64/pkgconfig
    LESSOPEN=||/usr/bin/lesspipe.sh %s
    XDG_RUNTIME_DIR=/run/user/1001
    _=/usr/bin/env

cat .bashrc

if [ -f /etc/bashrc ]; then

    . /etc/bashrc

fi

    export PATH=$HOME/localperl/bin:$HOME/usr/bin:$HOME/usr/libexec:$PATH
    export LD_LIBRARY_PATH=$HOME/usr/lib:$HOME/usr/lib64
    export C_INCLUDE_PATH=$HOME/usr/include
    export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
    export PKG_CONFIG_PATH=$HOME/usr/lib/pkgconfig:$HOME/usr/lib64/pkgconfig

 brew config

    HOMEBREW_VERSION: >=2.2.0 (shallow or no git repository)
    ORIGIN: (none)
    HEAD: (none)
    Last commit: never
    Core tap: N/A
    HOMEBREW_PREFIX: /home/test/usr
    HOMEBREW_REPOSITORY: /home/test/.linuxbrew/Homebrew
    HOMEBREW_CELLAR: /home/test/usr/Cellar
    HOMEBREW_CASK_OPTS: []
    HOMEBREW_MAKE_JOBS: 1
    CPU: single-core 64-bit sandybridge
    Homebrew Ruby: 2.6.3 => /home/test/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/bin/ruby
    Clang: N/A
    Git: N/A
    Curl: 7.29.0 => /usr/bin/curl
    Kernel: Linux 4.14.35-1902.3.2.el7uek.x86_64 x86_64 GNU/Linux
    OS: Red Hat Enterprise Linux Server release 7.7 (Maipo)
    Host glibc: 2.17
    /usr/bin/gcc: 4.8.5
    glibc: N/A
    gcc: N/A
    xorg: N/A

Please copy and paste the exact command you’ve run and the complete and exact error message that it’s giving you.

e.g. 2 commands that are often used:

[test@testing ~]$ brew update

Error: Git is unavailable
Error: Failure while executing; /home/test/usr/bin/brew tap homebrew/core exited with 1.
Error: Git must be installed and in your PATH!

[test@testing ~]$ brew install git

Updating Homebrew…
Error: Git is unavailable
Error: Failure while executing; /home/test/usr/bin/brew tap homebrew/core exited with 1.
Error: Git must be installed and in your PATH!
Error: Git is unavailable
Error: Failure while executing; /home/test/usr/bin/brew tap homebrew/core exited with 1.

What does git version say?

[test@testing ~]$ which git

~/usr/bin/git

[test@testing ~]$ git version

git version 2.28.0

I solved the problem for Git by moving the .linuxbrew/Homebrew directory to ~/usr, then:
ln -s ~/usr/Homebrew/bin/brew ~/usr/bin
eval $ (~ /usr/bin/brew shellenv)

now brew knows where git is
Git: 2.28.0 => /home/test/usr/bin/git

but he is still looking for curl under curl: 7.29.0 => /usr/bin/curl

then i ran brew update what crashed bash shell for user test compellet in the end

brew update
==> Tapping homebrew/core
Cloning into ‘/home/test/usr/Homebrew/Library/Taps/homebrew/homebrew-core’…
remote: Enumerating objects: 779, done.
remote: Counting objects: 100% (779/779), done.
remote: Compressing objects: 100% (402/402), done.
remote: Total 953072 (delta 538), reused 567 (delta 377), pack-reused 952293
Receiving objects: 100% (953072/953072), 342.48 MiB | 6.70 MiB/s, done.
Resolving deltas: 100% (657706/657706), done.
Updating files: 100% (5488/5488), done.
Tapped 2 commands and 5230 formulae (5,513 files, 377.7MB).
==> Downloading … 100.0%
==> Installing dependencies for curl: patchelf, m4, gmp, mpfr, libmpc, zlib, binutils, linux-headers, glibc, isl@0.18, gcc, bzip2, pkg-config and openssl@1.1
==> Installing curl dependency: patchelf
==> Pouring patchelf-0.11.x86_64_linux.bottle.tar.gz
:beer: /home/test/usr/Cellar/patchelf/0.11: 7 files, 877.4KB
==> Installing curl dependency: m4
==> Pouring m4-1.4.18.x86_64_linux.bottle.tar.gz
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /home/test/usr
Could not symlink bin/m4
Target /home/test/usr/bin/m4
already exists. You may want to remove it:
rm ‘/home/test/usr/bin/m4’

To force the link and overwrite all conflicting files:
brew link --overwrite m4

To list all files that would be deleted:
brew link --overwrite --dry-run m4

Possible conflicting files are:
/home/test/usr/bin/m4
/home/test/usr/share/info/m4.info
/home/test/usr/share/info/m4.info-1
/home/test/usr/share/info/m4.info-2
/home/test/usr/share/man/man1/m4.1
==> Summary
:beer: /home/test/usr/Cellar/m4/1.4.18: 13 files, 1.1MB
==> Installing curl dependency: gmp
==> Pouring gmp-6.2.0.x86_64_linux.bottle.tar.gz
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /home/test/usr
Could not symlink include/gmp.h
Target /home/test/usr/include/gmp.h
already exists. You may want to remove it:
rm ‘/home/test/usr/include/gmp.h’

To force the link and overwrite all conflicting files:
brew link --overwrite gmp

To list all files that would be deleted:
brew link --overwrite --dry-run gmp

Possible conflicting files are:
/home/test/usr/include/gmp.h
/home/test/usr/share/info/gmp.info
/home/test/usr/share/info/gmp.info-1
/home/test/usr/share/info/gmp.info-2
/home/test/usr/lib/libgmp.a
/home/test/usr/lib/libgmp.so -> /home/test/usr/lib/libgmp.so.10.4.0
/home/test/usr/lib/libgmp.so.10 -> /home/test/usr/lib/libgmp.so.10.4.0
/home/test/usr/lib/libgmp.so.10.4.0
/home/test/usr/lib/pkgconfig/gmp.pc
==> Summary
:beer: /home/test/usr/Cellar/gmp/6.2.0: 23 files, 3.9MB
==> Installing curl dependency: mpfr
==> Pouring mpfr-4.1.0.x86_64_linux.bottle.tar.gz
:beer: /home/test/usr/Cellar/mpfr/4.1.0: 30 files, 7.8MB
==> Installing curl dependency: libmpc
==> Pouring libmpc-1.1.0.x86_64_linux.bottle.tar.gz
:beer: /home/test/usr/Cellar/libmpc/1.1.0: 13 files, 1.5MB
==> Installing curl dependency: zlib
==> Pouring zlib-1.2.11.x86_64_linux.bottle.tar.gz
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /home/test/usr
Could not symlink include/zconf.h
Target /home/test/usr/include/zconf.h
already exists. You may want to remove it:
rm ‘/home/test/usr/include/zconf.h’

To force the link and overwrite all conflicting files:
brew link --overwrite zlib

To list all files that would be deleted:
brew link --overwrite --dry-run zlib

Possible conflicting files are:
/home/test/usr/include/zconf.h
/home/test/usr/include/zlib.h
/home/test/usr/share/man/man3/zlib.3
/home/test/usr/lib/libz.a
/home/test/usr/lib/libz.so -> /home/test/usr/lib/libz.so.1.2.11
/home/test/usr/lib/libz.so.1 -> /home/test/usr/lib/libz.so.1.2.11
/home/test/usr/lib/libz.so.1.2.11
/home/test/usr/lib/pkgconfig/zlib.pc
==> Summary
:beer: /home/test/usr/Cellar/zlib/1.2.11: 12 files, 393.3KB
==> Installing curl dependency: binutils
==> Pouring binutils-2.34.x86_64_linux.bottle.1.tar.gz
:beer: /home/test/usr/Cellar/binutils/2.34: 4,665 files, 279.9MB
==> Installing curl dependency: linux-headers
==> Pouring linux-headers-4.4.80.x86_64_linux.bottle.tar.gz
:beer: /home/test/usr/Cellar/linux-headers/4.4.80: 772 files, 3.6MB
==> Installing curl dependency: glibc
==> …/configure --disable-debug --disable-dependency-tracking --disable-silent-rules --prefix=/home/test/u
==> make
==> make install
==> Installing locale data for en_US.UTF-8
==> /home/test/usr/Cellar/glibc/2.23/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
:beer: /home/test/usr/Cellar/glibc/2.23: 1,402 files, 41.5MB, built in 64 minutes 53 seconds
==> Installing curl dependency: isl@0.18
==> Pouring isl@0.18-0.18.x86_64_linux.bottle.tar.gz
==> Caveats
isl@0.18 is keg-only, which means it was not symlinked into /home/test/usr,
because this is an alternate version of another formula.

For compilers to find isl@0.18 you may need to set:
export LDFLAGS="-L/home/test/usr/opt/isl@0.18/lib"
export CPPFLAGS="-I/home/test/usr/opt/isl@0.18/include"

For pkg-config to find isl@0.18 you may need to set:
export PKG_CONFIG_PATH="/home/test/usr/opt/isl@0.18/lib/pkgconfig"

==> Summary
:beer: /home/test/usr/Cellar/isl@0.18/0.18: 81 files, 6.3MB
==> Installing curl dependency: gcc
==> Pouring gcc-5.5.0_7.x86_64_linux.bottle.tar.gz
==> Creating the GCC specs file: /home/test/usr/Cellar/gcc/5.5.0_7/bin/…/lib/gcc/x86_64-unknown-linux-gnu/
:beer: /home/test/usr/Cellar/gcc/5.5.0_7: 1,348 files, 174.2MB
==> Installing curl dependency: bzip2
==> Pouring bzip2-1.0.8.x86_64_linux.bottle.tar.gz
:beer: /home/test/usr/Cellar/bzip2/1.0.8: 30 files, 510KB
==> Installing curl dependency: pkg-config
==> ./configure --prefix=/home/test/usr/Cellar/pkg-config/0.29.2_4 --disable-host-tool --with-internal-glib
==> make
==> make install
:beer: /home/test/usr/Cellar/pkg-config/0.29.2_4: 11 files, 704.1KB, built in 7 minutes 59 seconds
==> Installing curl dependency: openssl@1.1
==> perl Makefile.PL INSTALL_BASE=/home/test/usr/Cellar/openssl@1.1/1.1.1g/libexec
Last 15 lines from /home/test/.cache/Homebrew/Logs/openssl@1.1/01.perl:
2020-08-18 18:23:12 +0200

perl
Makefile.PL
INSTALL_BASE=/home/test/usr/Cellar/openssl@1.1/1.1.1g/libexec

Can’t locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /home/test/usr/Cellar/openssl@1.1/1.1.1g/libexec/lib/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 8.
BEGIN failed–compilation aborted at Makefile.PL line 8.

READ THIS: https://docs.brew.sh/Troubleshooting

Already up-to-date.
[test@testing ~]$ brew config
/bin/bash : : ELF: : Error 18446744071780639061

    ls: ▒▒g▒:ELF:  : Error 1934348629

[test@testing ~]$ env

    env:  ▒/: ELF:  : Error 18446744072728518997

[test@testing ~]$ ls

    ls: ▒4_{: ELF:  : Error 627806549

Your setup looks messed up now. If I understand correctly, your ~/usr contains stuff from outside Homebrew, and now you’ve tossed Homebrew itself into the pot. As you’ve already experienced, Homebrew doesn’t deal well with this, and name clashes and miscellaneous breakage are the result.

(Incidentally, this is true for every package manager I’ve encountered over the years. None of them handle “namespace clashes” gracefully, and if you try to run two package managers in the same hierarchy, or even mixing one package manager and manually-installed binaries, There Will Be Trouble.)

If anchoring your Homebrew install under /home/linuxbrew/.linuxbrew is not an option, pick a directory besides ~/usr and install Homebrew entirely under it. Ideally, when you run brew config, you should see HOMEBREW_PREFIX listed but not HOMEBREW_REPOSITORY or HOMEBREW_CELLAR.

the problem lies with LD_LIBRARY_PATH and all the libraries that I have already complicated for Git installation. I had to comment on LD_LIBRARY_PATH and log out and then log in again and delete the symlinks for m4, gmp, zlib and insert new ones.
first with

    brew link --overwrite --dry-run {m4, gmp, zlib} 

then with

    brew link --overwrite {m4, gmp, zlib}

almost everything looks fine now