# Compare installed packages between two FreeBSDs



## usakhncit (May 27, 2021)

Hi
I have installed FreeBSD (12.2-RELEASE) on two systems (Say, hosts: FB-1 and FB-2). FB-1 was installed six months ago and contains a lot of packages that were installed from Repo during this time period. However, FB-2 is a fresh install and contains few package installed from Repo. Now I want to compare installed packages between these two OSes, that is which packages are present in FB-1, but are missing from FB-2. One method that comes to my mind is:

```
pkg info > FB-1-Packages
pkg info > FB- Packages
diff FB-{1,2}-Packages
```
I am at work and I cannot access these two FreeBSD systems for next few hours, however, I suspect that this is not the correct way to compare packages. Can you help me in this regard?
Thanks


----------



## SirDice (May 27, 2021)

Look at the output from `pkg leaf` or `pkg prime-list` and compare those. You could use `pkg info` but that will also show all automatically installed dependencies, which you shouldn't install by hand (that messes up pkg-autoremove(8)).


----------



## zirias@ (May 27, 2021)

Use `pkg query -e '%a = 0' %n` to disregard versions and only consider packages not installed automatically as dependencies.

*edit* ok, `pkg prime-list` does exactly the same


----------



## mer (May 27, 2021)

Not enough coffee.  Zirias beat me to it.  The query he shows is the same as the prime-list alias.
And of course I should have read SirDice reply closer 

I like using "pkg prime-list" for this.  prime-list is an alias (pkg alias) that resolves to 'query -e '%a = 0' '%n''  (those are single quotes).  It basically gives you a list of just package names, like (snipped example):

```
drm-kmod
droid-fonts-ttf
emacs
evince-lite
falkon-qtonly
firefox
gimp
git
```


----------



## usakhncit (May 27, 2021)

SirDice said:


> Look at the output from `pkg leaf` or `pkg prime-list` and compare those. You could use `pkg info` but that will also show all automatically installed dependencies, which you shouldn't install by hand (that messes up pkg-autoremove(8)).





Zirias said:


> Use `pkg query -e '%a = 0' %n` to disregard versions and only consider packages not installed automatically as dependencies.
> 
> *edit* ok, `pkg prime-list` does exactly the same





mer said:


> Not enough coffee.  Zirias beat me to it.  The query he shows is the same as the prime-list alias.
> I like using "pkg prime-list" for this.  prime-list is an alias (pkg alias) that resolves to 'query -e '%a = 0' '%n''  (those are single quotes).  It basically gives you a list of just package names, like (snipped example):
> 
> ```
> ...


Thanks. I will try it and come back with results in few hours.


----------



## SirDice (May 27, 2021)

Yes, `pkg prime-list` is an alias. The nice thing about that one is that you can create a text file from it and feed that to pkg-install(8) on another machine.


----------



## mer (May 27, 2021)

SirDice said:


> Yes, `pkg prime-list` is an alias. The nice thing about that is that you can create a text file from it and feed that to pkg-install(8) on another machine.


I ran across it in that context, has proven useful over the years.


----------



## Alain De Vos (May 27, 2021)

```
pkg query -e "%a = 0" "%o" | sort
```


----------

