# Checking for port before install/compile



## kclark (Dec 6, 2013)

I've always wondered this about the ports tree and the package management software. Why doesn't the system check if a port has been installed before starting the download and/or compile process? To be fair, I haven't tried PKGNG yet and I do understand that FreeBSD isn't in the business of checking your commands before they have been executed, I would think this is something easy to fix and output some warnings before the process starts and ask if you want to continue. In the past I've waited hours on ports to compile and forgot to check before hand if something was already there. Again, I know the burden sits with me to do my homework first but it's still a question I've been meaning to ask for some time now. Is there some logic behind it or is this just one of those things?


----------



## kpa (Dec 6, 2013)

It's not possible at the moment to know by querying  the package database if the port is already installed with the exact port options set for the port as the user wants them to be set. It is possible to query the options from a package with PKGNG but the ports(7) infrastructure still has to support the older package format that knows nothing about the options set at the build time.

Then there is the fact that the ports build/install procedure is done in such a way that checking if the port already installed initially does not make much sense. That's because it should always be possible to execute all phases (fetch/patch/build/stage, I may forget something) before make install without the system telling you that the port is already installed and can not continue.

Also the  ports system has to work without even when the package registration is turned off (it can be done) and under that condition it's impossible to first query the package database first to see if a port is installed because it's not known if the previously installed ports used package registration or not.

The ports tree can also be used for various types of cross-install purposes, not just for installing on the machine itself. For example, this is how you could install a port on a hard drive that has another copy of FreeBSD installed and is mounted at /mnt:

`make -C /usr/ports/net/mtr DESTDIR=/mnt`

Testing every case of "not installed here but installed there" before launching the build in such a case is way too complicated and has to be postponed until the actual package registration is due.


----------



## kclark (Dec 6, 2013)

Dang, thanks for the detailed answer!  There was a lot more to it than I figured there would be.


----------

