OSX package management from the commandline, part 1

OSX package management from the commandline, part 1

Wed 10 February 2016

Some commands that can be useful when you need to install / remove packages from the commandline osx.

Get an overview, receipts and bomfiles

When a package is installed, a receipt (plist) and a bill of materials (bomfile) are also placed on your system.

The receipts and the bomfiles is binary files and you can use defaults and lsbom to read them.

# man defaults
# man lsbom

The receipts and bomfiles are usually located in: /var/db/receipts or ~/Library/Receipts/

# cd /var/db/receipts
# ls

You can read the receipts.plist files with the defaults command. This is metadata about the installed application.

# defaults read /var/db/receipts/uk.co.canimaansoftware.clamxav-engine-installer.plist
{
    InstallDate = "2016-05-04 07:38:17 +0000";
    InstallPrefixPath = "usr/local/clamXav";
    InstallProcessName = installer;
    PackageFileName = "engine.pkg";
    PackageIdentifier = "uk.co.canimaansoftware.clamxav-engine-installer";
    PackageVersion = "0.99.1";
    PathSHA1Checksums =     {
    };
}

You can read the bomfiles with the lsbom command. This is fileinformation about the installed application.

# lsbom uk.co.canimaansoftware.clamxav-engine-installer.bom
.   40755   0/0
./0.99.1_update_1   100644  0/0 0   4294967295    
...    
./share/man/man8/clamav-milter.8    100644  0/0 962 3292246713
./share/man/man8/clamd.8    100644  0/0 6322    507118410

... or you can use the pkgutil to retrieve the information.

# pkgutil --pkgs
com.128bittech.FreeFonts
com.acdsystems.acdsee
...
wifiexplorer
net.sourceforge.Gutenprint-5.2.9

Get information about a specific package

# pkgutil --files uk.co.canimaansoftware.clamxav-engine-installer
0.99.1_update_1
0.99.1_update_2
...
share/man/man8/clamav-milter.8
share/man/man8/clamd.8

# pkgutil --pkg-info uk.co.canimaansoftware.clamxav-engine-installer
version: 0.99.1
volume: /
location: usr/local/clamXav
install-time: 1462347497

Get reverse information about an application

If you have an application that you want to get information about you can use pkgutil to get some info.

# pkgutil --file-info /Applications/Mail.app
volume: /
path: /Applications/Mail.app

pkgid: com.apple.pkg.Essentials
pkg-version: 10.9.0.1.1.1306847324
install-time: 1394632076
uid: 0
gid: 0
mode: 755

pkgid: com.apple.pkg.update.os.10.9.3.13D65.delta
pkg-version: 1.0.0.0.1.1306847324
install-time: 1400222538
uid: 0
gid: 0
mode: 755

pkgid: com.apple.pkg.update.os.10.9.4.13E28.delta
pkg-version: 1.0.0.0.1.1306847324
install-time: 1405059341
uid: 0
gid: 0
mode: 755

.... which will show you which pkgid that is responsible for the actual Software.app bundle.

Install and remove software

It is easy to install a package with the program installer.

# man installer

Removing a package is a bit harder though, and it involves reading the bomfile and removing all resources listed in the bomfile with rm.

Install a package

# installer -pkg /path/to/somename.pkg -target /

Remove a package

Get a list of all the files. The safest approach is to delete the files by hand.

# pkgutil --only-files --files uk.co.canimaansoftware.clamxav-engine-installer
0.99.1_update_1
0.99.1_update_2
...
share/man/man8/clamav-milter.8
share/man/man8/clamd.8

Get a list of all the directories. The safest approach is to delete the directories by hand.

# pkgutil --only-dirs --files uk.co.canimaansoftware.clamxav-engine-installer
3rd Party Licences
bin
...
share/man/man5
share/man/man8

Forget a packagereceipt

After we have removed the program, we also have to remove the receipt and bomfile.

# pkgutil --forget no.mbmedia.pkg.somename

Learn more