Making a package from a port on FreeBSD

Some times is it the simple things that people don’t know. For example, I have always just installed software from ports. Every now and then I would use pkg_add -r to pull a pre-made package from a FreeBSD package server. But I have never actually made a package myself. I have been using FreeBSD for 10 years and many consider me an expert in some areas.  Well, like I always say, it is possible to be an expert in many areas and still be a newbie in some areas.

Recently, I am looking into steps to make a BSD appliance and so I want to keep the system as minimal as possible. So I want to build packages on on a separate build box. So I suddenly realized that I have never made a package myself and I wasn’t exactly sure how.

So is it hard to convert a port into a package? Of course not. If you want to make a package from a port, and you are familiar with ports already, then all you have to do is run make package, and you may want to make the dependent packages as well.

If you need some more granular steps, I will provide them. You just need to follow some simple steps:

FreeBSD make package

Lets assume you want to install lighttpd.

  1. Download the latest ports tree. See this article: How to install ports on FreeBSD?
  2. Search for the port you want.
    #
    #
    cd /usr/ports
    make search name=lighttpd

    The output should look as follows:

    Port: lighttpd-1.4.28_4
    Path: /usr/ports/www/lighttpd
    Info: A secure, fast, compliant, and very flexible Web Server
    Maint: mm@FreeBSD.org
    B-deps: libtool-2.2.10 pcre-8.10 pkg-config-0.25_1
    R-deps: pcre-8.10
    WWW: http://www.lighttpd.net/
  3. Look at the R-Deps. R is short for Run and deps is short for dependencies. If you want a package for lighttpd, it requires pcre-8.10 to run, so you will need a package for pcre-8.10 as well.
    Note: B-deps are not need. B is for Build. These dependencies are only need to build the package.  Once the package is built, they are not needed, so you don’t need to create packages for them.
  4. Make the lighttpd package:
    #
    #
    cd /usr/ports/www/lighttpd
    make package
  5. This creates the file in the /usr/ports/www/lightpd. You may have a directory or share where you store your packages, and you can copy it there if you want. Especially if this is a build machine in a vm that you plan to revert, you need to copy this off the machine or you will lose it when you revert.
  6. Make the pcre package.
    #
    #
    cd /usr/ports/devel/pcre
    make package
  7. This creates the file in the /usr/ports/www/lightpd. You may have a directory or share where you store your packages, and you can copy it there if you want. Especially if this is a build machine in a vm that you plan to revert, you need to copy this off the machine or you will lose it when you revert.

Hopefully this helps you if you ever need to make your packages on one box.

This is also something great to do before an install fest so you can have the latest packages available. Lets say you want to do an install fest for a FreeBSD desktop, you could have all the latest Xorg and Fluxbox or KDE or GNOME packages already built.

Build machine notes
On your build machine “make package” will actually install the package in the process of building the package. However, that is not really a concern as this is a build machine. My recommendation is that you create a build machine in VirtualBox and snapshot it after you download ports. Usually you just continue making packages. When you decide it is time to go back to a clean system, 1) revert your snapshot, 2) update your ports tree, 3) make your new packages.

4 Comments

  1. Zoltán says:

    What's that mean?

    "Copy it to where you need to copy it."

  2. Francisco says:

    You can also make a package from an already installed port:
    pkg_create -b

Leave a Reply

How to post code in comments?