I am trying to count the total number of homebrew formulas. I've done a wildcard search and directed the output to a text file and counted the lines using brew search /.*/ | wc -l.
This produces only 3,142 formulas, 1/5 the number I found for Macports. However, I've noticed that Macports also has a lot of duplicate packages, listing both the meta package and it's various dependent packages. Is there a way to break out those dependent packages in Homebrew? What about Macports, is there a way to filter out the number of redundant dependent packages?
Finally, is there a way to force Homebrew to list versions?
You should be comparing the number of MacPorts source packages to Homebrew. For example
tar tf /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports.tar | grep Portfile | wc -l
Maybe there is a better way.
To get a list of package versions in Homebrew, you can try something like this:
for formula in $(brew search); do brew info $formula | grep "^$formula"; done
Related
What I think that I've understood about home-manager.
Instead of using
nix-env iA packageToBeInstalled
you write a list of package in a file (/home/nixos/.config/nixpkgs/home.nix that I from now on call just home.nix)
you run
home-manager switch
and the package are installed.
But I have already installed some packages with nix-env. (home-manager for instance)
I would like to have my configuration save just in home.nix in order to just have to import it and execute home-manager switch to import the exact same configuration in a other OS.
Therefore I need a command replicating my configuration in home.nix.
I am not aware of a tool that fully automates this.
The nix-env list of installed packages is maintained in ~/.nix-profile/manifest.nix, but does not contain the attribute path, which is the "name" you need to use in such configuration files.
To find the attribute paths for the things you've installed, you may first create an index of sorts based on your current nixpkgs (NIX_PATH etc):
nix-env -qaP >packages.tmp
and then use it to look up each package.
Here's a one-liner that doesn't work for all packages.
nix-env -q | while read name; do grep "$name" <packages.tmp; done
So make sure to read through nix-env -q yourself and look up anything that's missing using for example https://search.nixos.org/packages.
To finalize, remove the imperatively installed packages with nix-env -e, check nix-env -q, and rm packages.tmp.
I'm having trouble searching for the list of all casks when I run the command for it.
brew search --casks
I get the error you see in the picture.
Error: Invalid usage: This command requires at least 1 text or regex argument.
If anyone has had similar problems please share.
You need at least one string to search for.
$ brew search --casks fire
==> Casks
firefly firealpaca firestorm
firefox-beta firebase-admin firestormos
firefox-developer-edition firebird-emu fireworks
firefox-esr firecamp multifirefox
firefox-nightly firefox ✔ spitfire-audio
If you really need to find all available casks, you can use an empty arg like this:
brew search --casks ''
I want to list all keg-only formulas installed on a machine. Could anybody show me a single command that can do this job? I haven't find a solution to do this task.
I've had success running this command to get formulas that are installed as keg-only:
[$]> brew info --installed --json=v1 | jq 'map(select(.keg_only == true)) | map(.name)'
References:
https://github.com/Homebrew/legacy-homebrew/issues/26903
https://github.com/Homebrew/homebrew-core/issues/26165
Over time, I've installed a number of packages with Homebrew, mostly from the default repo of formulae (homebrew-core), but some from other locations via brew tap.
Now I'm putting together some install scripts to make my dev environment more reproducible, and I'm trying to figure out which packages can be installed by a simple brew install and which require a brew tap beforehand.
The ability to query brew has proved useful for figuring out which options I used for each package, but not for this tap-related question. Is there a way to do this without manually going through each package and seeing where it's available?
I found a couple ways that work.
brew list --full-name
Slower, but a little more informative:
brew info $(brew list) | grep '^From:' | sort
This expression would return a list of installed 3rd party packages only:
brew list --full-name -1 | grep /
…for the respective list of taps in use, try:
brew list --full-name -1 | grep / | cut -d"/" -f1 -f2 | sort | uniq
The brew list --full-name variants in the other answers did not work for me (in 2022). This, however, does:
brew list -1 | xargs brew info | grep '^From:'
Alternatively, to see only casks, use this:
brew list --cask -1 | xargs brew info --cask | grep '^From:'
... or only leaves:
brew leaves | xargs brew info | grep '^From:'
In my CI-setup, i would like to make sure that the newest version of a given formula is installed, regardless of whether it is already installed or not.
i'm currently using something like:
brew update
brew install FORMULA || (brew upgrade FORMULA && brew cleanup FORMULA)
What are the pitfalls with that approach? Is there a nicer approach to the problem (e.g. by first querying whether FORMULA is already installed, rather than relying on brew install to fail only if FORMULA is installed)?
I you want to install a Homebrew package if it does not already exist, and upgrade it otherwise, the best solution is to use Homebrew Bundle which is officially part of the Homebrew family. If that doesn't work for you, and you want to roll your own solution, you should reference at the suggestions below.
There are other situation where a brew install might fail, other than a package already being installed. I'm not sure, but it doesn't look like the brew install command emits an exit status other than 1 on failure, so you have two options:
Search stderr for "not installed" and check against that
Use a different approach
The most common approach I've seen used for this purpose is to check if the package is installed with the command brew ls --versions:
function install_or_upgrade {
if brew ls --versions "$1" >/dev/null; then
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade "$1"
else
HOMEBREW_NO_AUTO_UPDATE=1 brew install "$1"
fi
}
You'll want to use HOMEBREW_NO_AUTO_UPDATE=1 if you're installing multiple packages so that Homebrew does not try to update in between each install/upgrade.
I've been using the following. Depending on the use case, I'll use a shell function as follows:
function smart_brew() {
HOMEBREW_NO_AUTO_UPDATE=1 brew `brew ls --versions "$1" | wc -l | xargs expr | sed 's/0/install/' | sed 's/1/upgrade/'` "$1"
}
and sometimes as a definition in a Makefile:
define smart_brew
HOMEBREW_NO_AUTO_UPDATE=1 brew `brew ls --versions "$(1)" | wc -l | xargs expr | sed 's/0/install/' | sed 's/1/upgrade/'` "$(1)"
endef
dev:
$(call smart_brew,formula)
Same basic idea