Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

brew --prefix <formula> shows path to latest version rather than installed version #12571

Closed
adammw opened this issue Jun 3, 2012 · 10 comments
Closed

Comments

@adammw
Copy link
Contributor

adammw commented Jun 3, 2012

My .bashrc has the line:

PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"

to use the GNU ls, etc. commands from coreutils.

Recently, I ran brew update but did not brew upgrade coreutils. Opening new terminals meant that the path was being set incorrectly and I ended up running the standard Mac OS ls, etc. binaries because brew --prefix coreutils was returning /usr/local/Cellar/coreutils/8.17 even though only 8.16 was installed. The wiki says that brew --prefix <formula> prints where the formula is installed, meaning that it's behaviour of using the latest version rather than the installed version is incorrect, and it will cause problems with all automated scripts (such as the recommended bashrc addition above) that use it.

@jacknagel
Copy link
Contributor

It might be a bit unintuitive but it's not really bug, or at least it has always behaved this way. I've always understood

Display the location in the cellar where formula is or would be installed.

to mean exactly that, where "formula" really means only "formula", and once something is installed it is no longer a "formula".

See the last few comments on #8196 for discussion about this.

@jacknagel
Copy link
Contributor

I should add that the robust way to do what you want is

$(brew --repository)/Library/LinkedKegs/<formula>

@adammw
Copy link
Contributor Author

adammw commented Jun 4, 2012

I didn't think that LinkedKegs worked for keg-only formulas... I just installed the curl formula which is keg-only and it did not create a link in LinkedKegs. Also, simply relying on the linked kegs directory being in the path above may be incorrect or at least may break in the future if #9811 gets done.

Is there any progress on adding a --keg command or similar to provide what I (and I expect most people who use brew --prefix <formula> in scripts) expect?

P.S. I see now in the man page it being described like that, I think the Wiki (brew command page) should be updated to match. And yes, it is very unintuitive.

@mxcl
Copy link
Contributor

mxcl commented Aug 6, 2012

Yeah, it's wrong. Will fix for brew2!

@adamv
Copy link
Contributor

adamv commented Sep 1, 2012

Probably can't change brew --prefix thing behavior at this point, but will accept patches to add new/alternate commands. Should be an external command to start, I think.

Something like brew path foo with switches for thinks like --prefix, --cellar, --keg, --whatever.

@mxcl
Copy link
Contributor

mxcl commented Sep 1, 2012

You can now do this:

`brew --prefix`/opt/ack

Provided you installed recently, the opt prefix is the prefix of the installed keg.

@bdefore
Copy link

bdefore commented Sep 11, 2012

I was bit by this issue as well. The percona-server documentation states you need to run the following to initialize the DB:

mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix percona-server)" --datadir=#{var}/percona --tmpdir=/tmp

The brew --prefix call for me results in:

/usr/local/Cellar/percona-server/5.5.27-28.1

But my installation is in:

/usr/local/Cellar/percona-server/5.5.27-28.0

Replacing the basedir with the actual path resolves the issue, but it's not apparent at first why this fails.

@mxcl
Copy link
Contributor

mxcl commented Sep 13, 2012

Considering how we treat brew --prefix, I will update it to use the opt prefix.

@mxcl
Copy link
Contributor

mxcl commented Sep 13, 2012

6c5f175

@mxcl mxcl closed this as completed Sep 13, 2012
@mmzoo
Copy link

mmzoo commented Jan 8, 2013

I just ran into this when trying to use the same mysql_install_db command mentioned by bdefore above (using the current homebrew master). So I assume the issue still exists, the commit above has been reverted again.

I would like to know what I can do to get hold of the path to the currently installed version without using grep too much :)

For simplicity I simply upgraded to the newest mysql version to match the path which is provided by brew --prefix mysql again, but that can't be the solution... I'd be fine as long as this will be fixed in brew2?

Thanks for the efforts by the way. Every time I look through the homebrew code I'm impressed by the brains behind it :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants