# Removing dependencies



## hruodr (May 20, 2017)

I want to delete a package and its dependencies that are not dependencies of other packages, but not to do autoremove (that may delete much). What should I do?

As I understand, with -R are not deleted dependencies, but "packages that require the listed packages as well".


----------



## talsamon (May 20, 2017)

Let's play on the commandline (bash)
`for depfiles in `pkg info -d packagename`; do if [ `pkg info -r $depfiles |wc -l` == 2 ]; then  echo $depfiles;fi;done |tee -a dellist`

and
`pkg delete `cat dellist``

but better is:
you use `pkg set` to prevent packages removed by `pkg autoremove`.

(I edit it. In the first version was a typo).


----------



## hruodr (May 21, 2017)

It is good to know that there is no simple command for the simple task, but that a simple script can be written.


----------



## talsamon (May 21, 2017)

The command `pkg autoremove` normally does not remove packages that still needed. It only removes packages
that does not refere to any installed packages and are registered as automatic.
With `pkg set -A0` you can set every package to register as non-automatic. So `pkg autoremove` does not touch it.
If `pkg autoremove` does something different on your system, there is something wrong with your installed ports or packages.


----------



## hruodr (May 22, 2017)

Yes, `pkg set -A0` is a good alternative if one knows all automatic packages that one still needs. But if one only knows that one does not need some packages, for example the ones installed as dependence of a specific package, then it is danger to delete any non-automatic. This is for example the case if you compiled some programs in /usr/opt and the configuration scripts decided about the dependencies.


----------

