Sometimes, you might want to create a binary package of an application you have installed on your system. For example, if you compiled OpenOffice.org with some custom options, such as WITH_KDE or WITH_GNUGCJ, and you want to back it up, you want to install it on your other three FreeBSD systems without spending the time compiling it on each computer, or you want to give it to a friend, creating a binary package is a simple way to redistribute the application in quick-to-install binary form with your custom options.
First, we have to find the full name of the installed application, i.e. name with version number.
pkg_info | grep openoffice
Which returns:
en-US-openoffice.org-2.0.0 Integrated wordprocessor/dbase/spreadsheet/drawing/chart/br
So, to create a binary package of this application,
pkg_create -b en-US-openoffice.org-2.0.0
A minute or two later, you should see the following file in the current directory: "en-US-openoffice.org-2.0.0.tgz". Anyone you give this file to can then install it simply by typing:
pkg_add en-US-openoffice.org-2.0.0.tgz
Make sure, of course, to specify the full path to the file, if you do not execute the "pkg_add" command from the same directory where the file is located. Also note that dependencies of the package will not be automatically downloaded, since we're installing the package from a local file. Any dependencies that cause the install to fail will need to be installed from Ports or Packages before the package we created will successfully install on another system.
If you have the package's dependencies already installed, but it is complaining because you have different versions of these dependencies than those required by the package installed, you can probably run the following command relatively safely:
pkg_add -f en-US-openoffice.org-2.0.0.tgz
Which will force the package to install even though not all of its requisite dependencies are present on the target system.
As of FreeBSD 6.0-RELEASE, it is also possible to create packages of the installed application's dependencies at the same time you create a package of the installed application. This might make installing the package on another system easier (good idea to create a new directory and run this command within it):
pkg_create -Rb en-US-openoffice.org-2.0.0
After a few minutes, you should have packages of OpenOffice.org and a bunch of its dependencies in the current directory. Doing an "ls" will reveal an impressive list, along the order of this:
ORBit2-2.12.4_1.tgz jpeg-6b_3.tgz
atk-1.10.3.tgz libIDL-0.8.6_1.tgz
bitstream-vera-1.10_2.tgz libXft-2.1.7.tgz
cairo-1.0.2_1.tgz libbonobo-2.10.1_2.tgz
cdparanoia-3.9.8_7.tgz libiconv-1.9.2_1.tgz
en-US-openoffice.org-2.0.0.tgz libxml2-2.6.22.tgz
expat-1.95.8_3.tgz linc-1.0.3_4.tgz
fam-2.6.9_6.tgz openldap-client-2.2.29.tgz
fontconfig-2.3.2,1.tgz pango-1.10.1.tgz
freetype2-2.1.10_1.tgz perl-5.8.7.tgz
gconf2-2.12.1.tgz pkgconfig-0.20.tgz
gettext-0.14.5.tgz png-1.2.8_2.tgz
glib-2.8.4.tgz popt-1.7.tgz
gnomehier-2.0_7.tgz samba-libsmbclient-3.0.20b_2.tgz
gnomemimedata-2.4.2.tgz shared-mime-info-0.16_2.tgz
gnomevfs2-2.12.2.tgz tiff-3.7.4.tgz
gtk-2.8.8.tgz xorg-fonts-encodings-6.8.2.tgz
hicolor-icon-theme-0.5.tgz xorg-fonts-truetype-6.8.2.tgz
howl-1.0.0.tgz xorg-libraries-6.8.2.tgz
That's a lot of packages! Place these in the same directory on the target system, and "pkg_add en-US-openoffice.org-2.0.0.tgz" as you did with the previously created package. This time, all of the application's dependencies are present locally, so they should be added as well.
One incredibly important note about packages. If you create a package in FreeBSD 5.x and attempt to install it on a FreeBSD 6.x system, you'll probably be okay so long as the 6.x system has compat5x enabled. However, you CANNOT install a package created in 6.x on a 5.x system. There is no "compability mode" allowing the older system to run packages created on the newer one. Installing a 6.x package on 5.x will not work, and will give you nothing but headaches.