256

I installed some packages via brew. But I can not find where they are.

I can not get access by typing hping on terminal

% brew install hping
(git)-[master] 
Warning: hping-3.20051105 already installed
klanomath
  • 66,391
  • 9
  • 130
  • 201
poc
  • 2,779

15 Answers15

297

Use the following to show the installation path of a package:

brew info hping

Example output:

pcre: stable 8.35 (bottled)
http://www.pcre.org/
/usr/local/Cellar/pcre/8.35 (146 files, 5.8M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/pcre.rb
==> Options
--universal
    Build a universal binary
nyi
  • 3,101
  • 21
    Is it possible to get only path? In my case I want to use clang from llvm and after "brew install llvm" clang is still apple's, but one from llvm binaries is what I need. – okutane Sep 09 '16 at 06:51
  • 1
    BTW brew doctor might help you understand issues as well. – jakub.g Feb 28 '17 at 16:34
  • 6
    @okutane You would need to assemble the path yourself. As a crude example, you could do echo "$(brew --cellar llvm)/$(brew list --versions llvm | tr ' ' '\n' | tail -1)/bin/clang" – nburr Mar 07 '18 at 16:37
  • 6
    Depending on your specific needs, brew --prefix hping (from @capripot's answer) may do the trick. – waldyrious Jan 04 '19 at 17:59
  • Usually brew stores symlinks to the latest bin in /usr/local/bin/ – Mint Aug 08 '21 at 08:20
  • 2
    ^ although note that on M1 Macs, they live in /opt/homebrew/bin/ – Leland May 16 '22 at 22:41
59

To figure out where your formula is installed, do brew --prefix hping

You can also relink your hping binary by doing brew unlink hping && brew link hping

Also maybe your $PATH is not well defined. Does the list given by echo $PATH contains the result given by echo $(brew --prefix)'/bin:'$(brew --prefix)'/sbin'? This path should be toward the beginning of the list to be prioritized over system binaries, surely before /usr/bin.

To do so, you can add this at the end of your ~/.zshrc or ~/.bashrc:

export PATH=$(brew --prefix)/bin:$(brew --prefix)/sbin:$PATH

As a result, after opening a new terminal or doing source ~/.zshrc, you'll be able to echo your correct path as:

$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
Capripot
  • 719
  • 5
    Thank you, brew --prefix <command> was exactly what I needed. – waldyrious Jan 04 '19 at 17:57
  • This does not work for "cask" packages. – Pointy Oct 08 '22 at 13:31
  • 1
    I used the hint here to resolve a dependency against Postgres on an M1 w/Monterey. This, plus brew info package as mentioned above, and this FAQ, cleared things up for me: https://docs.brew.sh/FAQ#why-is-the-default-installation-prefix-opthomebrew-on-apple-silicon – learning2learn Jan 24 '23 at 08:38
40

brew --cellar prints the directory which is the default location on macOS. You'll see sub-directories in there for all your installed formulae.

nohillside
  • 100,768
11

Try this command

brew --cellar <FORMULA>

e.g.

brew --cellar hping
nohillside
  • 100,768
10

Normally, homebrew installs packages into /usr/local/bin. So you need to check that your PATH contains that directory, like this:

echo $PATH

Also, try running

brew doctor

to make sure your setup is correct. If /usr/local/bin is not in your PATH, you need to edit ~/.profile and add a line like this:

export PATH=$PATH:/usr/local/bin

Then start a new Terminal (in order to re-read your login profile) and try again.

If all that fails, it must be installed somewhere else. You can search for it by running a command like this:

sudo find / -name hping -type f
  • 2
    These are symlinks. The actual packages are in /usr/local/Cellar as @PapaStanley points out. – Steve Aug 18 '15 at 01:06
  • @Steve why is it then that when i do ls -ld /usr/local/bin it looks like a regular directory? – barlop Aug 10 '19 at 15:09
  • @barlop Because not /usr/local/bin is a symlink, the files inside that directory placed there by Brew are symlinks. – Mecki Jan 07 '22 at 01:33
7

Inspired by @RubenLaguna, I came up with this to get the full path to the installed version of the default formula.

As shown in previous answers, to get the install path for a formula:

brew --prefix nmap

Returns a symlink to the install path:

/usr/local/opt/nmap

To expand the full path:

readlink -f $(brew --prefix nmap)
/usr/local/Cellar/nmap/7.92
4

To find your base installation directory for Homebrew, use one of the following commands:

brew --prefix
brew --cellar

The latter specifically returns the path of your Cellar folder.

3

I couldn't find any direct CLI option in brew to get the full path to the currently installed version of a formula but this would work as long as you are using bash:

echo $(brew --cellar asciidoctor)/$(brew info --json asciidoctor | jq -r '.[0].installed[0].version')
# /usr/local/Cellar/asciidoctor/1.5.8
1

I recommend adding the following line to your ~/.bash_profile (or the equivalent configuration file if you are using a different shell):

export HOMEBREW_CASK_OPTS="--appdir=/Applications"
ssc
  • 109
1

hping requires root privileges to run.

You probably need to add /usr/local/sbin to your PATH.

When I ran brew doctor:

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
    echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
jyap
  • 111
1

For anyone that lands here after googling, and/or for anyone who wants a list of packages that are installed as keg only, you can get this info from the brew JSON output.

List all installed packages:

brew info --json --installed

List keg only packages (jq tool required):

brew info --json --installed | jq -r '.[] | select(.keg_only == true) | .name'

List the path for keg only packages (again, jq tool required):

brew info --json --installed | jq -r '.[] | select(.keg_only == true) | .name' | while read name; do brew --prefix $name; done 
jmurphyau
  • 119
1

The real path to the directory containing versioned directories of the formula

brew --cellar <FORMULA>

Example

% brew --cellar spdlog            
/usr/local/Cellar/spdlog

Symlink to the current version of the formula (shorter)

This is what you want most of the time.

brew --prefix <FORMULA>

Example

% brew --prefix spdlog         
/usr/local/opt/spdlog
0

I installed some packages via brew. But I can not find where they are.

It seems that homebrew requires one to be explicit with things. Fortunately, a bit of escaping using brew --prefix can make this a no-brainer, for those who need to find the path for the pkg-config utility, e.g.

PKG_CONFIG_PATH=`brew --prefix hping`/lib/pkgconfig/ pkg-config --cflags hping

(Except this isn't going to work anyway, because it seems hping doesn't come with hping.pc .. although, in the case where package maintainers do put .pc files, this trick can be useful.)

ibisum
  • 101
0

If someone looking for real path of package:

In my case brew --cellar opencv3 gives /usr/local/Cellar/opencv

But find /usr/local/Cellar/ -type d -name "*opencv*" -maxdepth 1 gives

/usr/local/Cellar//opencv3(which is /usr/local/Cellar/opencv3 actually).

Headers:

/usr/local/Cellar/opencv3/3.4.1_1/include/

Libs:

/usr/local/Cellar/opencv3/3.4.1_1/lib/

mrgloom
  • 641
-1
brew list opencv

Output like this:

/usr/local/Cellar/opencv/4.5.2_4/bin/opencv_annotation
/usr/local/Cellar/opencv/4.5.2_4/bin/opencv_interactive-calibration
/usr/local/Cellar/opencv/4.5.2_4/bin/opencv_model_diagnostics
...

My brew version:

brew -v
> Homebrew 3.2.1
F566
  • 101
  • 1