0

While trying to install AWS SAM CLI on a linux box, I had to install Homebrew/Linuxbrew. The AWS package have a dependency to python 3, which I already have installed on my system. In the middle of the homebrew installation logs, I see this:

==> Pouring python-3.7.4.x86_64_linux.bottle.tar.gz
==> /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
==> /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
==> /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
==> Caveats
Python has been installed as
  /home/linuxbrew/.linuxbrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /home/linuxbrew/.linuxbrew/opt/python/libexec/bin

Following which:

$ which python3
/home/linuxbrew/.linuxbrew/bin/python3

This does not sit well with me, as it didn't warned before, left me no choice, and I trust my distribution a lot more than homebrew.

My first thought was to remove the package:

$ brew uninstall python3
Error: Refusing to uninstall /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
because it is required by aws-sam-cli, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python3

Which mean I can't simply remove it

Now, having a dependency installed is bearable, but not if it replace my system native package, so my question is:

Is there a way to tell homebrew to not mess up with my system in the future, and to get back my native python ?

  • The native python3 executable would be used if its directory is before /home/linuxbrew/.linuxbrew/bin in your $PATH. Net turning this into an answer because I don't know the answer to you actual question at the end (and I don't really know what you mean by "messing with my system"). – Kusalananda Aug 23 '19 at 14:57
  • By "messing with", I mean trying to replace native packages, like it did with python3. Moving brew in the PATH could be a solution, I think I ll remove it entirely from the PATH so that it become a non issue – DrakaSAN Aug 23 '19 at 15:01
  • Brew never replaced anything. It is very carefully keeping it's software separate from your base system. – Kusalananda Aug 23 '19 at 15:06
  • Have you tried uninstalling aws-sam-cli, homebrew's python, and then hombrew itself. and then using the debian packaged version of pip to install it - pip3 install aws-sam-cli? Or even examining the aws-sam-cli code to find out what lib modules it needs, installing the debian packages for them (if they exist), and then installing aws-sam-cli from the github repo? Vendor install instructions should always be viewed with suspicion because they care about their app, not your system....such instructions are often some awful brute force method that makes no effort to integrate with the system – cas Aug 24 '19 at 0:37
0

Linuxbrew will install packages that provide dependencies to packages that you install, as needed. Sometimes these dependencies (or for that matter, packages that you install with brew) will provide the same services or tools as software already present on your system. Linuxbrew will not replace software already installed by other means on your system, since what it installs is installed in a totally separate location (by design).

To make sure that commands provided by brew does not take precedence over commands installed in other ways, make sure that the various Linuxbrew bin directories are last in your $PATH, or at least after the bin directories holding your "native" commands on your system.

I believe that Linuxbrew adds the following to a user's ~/.bash_profile (or asks the user to add it, I don't remember):

eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)

(or something similar).

This causes the command

export PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH"

to be executed, which adds the Linuxbrew paths to the front of your $PATH.

You can run the brew shellenv command in your terminal and copy its output into your ~/.bash_profile file (there should be a number of export statements), replacing the corresponding call there completely, and changing the export PATH command into

export PATH="$PATH:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin"

This makes sure that commands in your default (non-Linuxbrew) $PATH have precedence over the brew commands. If this breaks any brew packages that depend on the Linuxbrew version of commands or not, I cannot say.

  • Couldn't connect over the week end to validate, but had the time to cool of and take a fresh look, that was exactly the problem. For my use, the commands do not break, so that's fine – DrakaSAN Aug 26 '19 at 8:28
  • Or, instead of copying and pasting the output, you can add something like this to your init file: oldPATH=PATH; eval $(...) ; export PATH=$oldPATH:/home/linuxbrew/.... That way, if brew shellenv gets updated later, you won't need to port that update to your init file. – T. Verron Dec 13 '19 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.