# HOWTO: Keep track of installed packages over time.



## Claud (Aug 1, 2012)

This is my first how-to so I hope it will be understood.
The problems I had with FreeBSD was that when I wanted to install a package I found out that it has many dependencies that I didn`t want and with pkg_delete(1) I could uninstall only that program, because I forgot what installed, so keeping a good clean system was a problem for me, so I found a solution.
*1. Take a snapshot of your installed programs before install,*

```
ls /var/db/pkg/ > ~/pkg_snap_before
```
*2. Install your program*

```
pkg_add -r program_name
```
****
A lot of dependencies installed.
****
If you find that you are not fond with the results proceed to step 3.
*3. Take another snapshot*

```
ls /var/db/pkg/ > ~/pkg_snap_after
```
*4. Uninstall the installed programs*

```
pkg_delete `grep -Fxvf ~/pkg_snap_before ~/pkg_snap_after`
```

This will revert the packages to the state that it was before installing your package.
Hope it helps someone.


----------



## vermaden (Aug 1, 2012)

About snapshotting ... think about making it more useful for longer retention, for example instead of *before* and *after* which is enough for 2 versions try something like that:
`% ls /var/db/pkg/ > ~/pkg_snap_$( date +%Y-%m-%d-%H-%M )`

Or even that with sorted output which is more 'friendly' for diff:
`% ls /var/db/pkg/ | sort -n > ~/pkg_snap_$( date +%Y-%m-%d-%H-%M )`

Example name:
`~/pkg_snap_2012-08-01-15-00`


----------



## Ogham (Aug 1, 2012)

As an alternative to snapshots, I find portmaster -L extremely useful for identifying installed ports that are no longer required.

This handbook entry explains it very succinctly: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports-using.html



> Portmaster groups ports into four categories:
> 
> Root ports (no dependencies, not depended on)
> 
> ...




```
# portmaster -L
===>>> Root ports (No dependencies, not depended on)
===>>> ispell-3.2.06_18
===>>> screen-4.0.3
        ===>>> New version available: screen-4.0.3_1
===>>> tcpflow-0.21_1
===>>> 7 root ports
...
===>>> Branch ports (Have dependencies, are depended on)
===>>> apache-2.2.3
        ===>>> New version available: apache-2.2.8
...
===>>> Leaf ports (Have dependencies, not depended on)
===>>> automake-1.9.6_2
===>>> bash-3.1.17
        ===>>> New version available: bash-3.2.33
...
===>>> 32 leaf ports

===>>> 137 total installed ports
        ===>>> 83 have new versions available
```

There is also this useful utility: ports-mgmt/pkg_cutleaves


----------



## Claud (Aug 1, 2012)

Hi, 
@vermaden , thanks for suggestions, but keep in mind that you cannot use snapshots too old because if a package was upgraded in the meantime it will be deleted.
@Ogham  From my knowledge portmaster uses ports data(will show that new version of package are available but those are not present as binary packages), my solution was for the use with binary packages only. portmaster -L shows new packages available in ports not as binary packages.

pkg_cutleaves for a simple installation of emacs (which installed 6 dependeces) shows me all the files that are not in other deps( about 54 packages including some i am using and exclude list is too long to use it), which is not a solution.


----------



## Ogham (Aug 1, 2012)

Claud said:
			
		

> @Ogham  From my knowledge portmaster uses ports data(will show that new version of package are available but those are not present as binary packages), my solution was for the use with binary packages only. portmaster -L shows new packages available in ports not as binary packages.



That is correct, it will show you updates available from the ports tree (and even in -stable packages there may not yet be a pre-compiled package).

It is the identification of Root/Trunk/Branch/Leaf installed packages that is useful when deciding which are no longer necessary and can be safely removed.



			
				Claud said:
			
		

> pkg_cutleaves for a simple installation of emacs (which installed 6 dependeces) shows me all the files that are not in other deps( about 54 packages including some i am using and exclude list is too long to use it), which is not a solution.



Yes, pkg_cutleaves is no 'magic bullet', it still requires the user to aid in the decision making - Which is definitely a good thing!


----------

