FreeBSD Ports: Making them Friendlier

Pages: 1 2

Getting Started

You can use ports out of the box, but it’s awkward if you’re not used to the process of building software by hand. Plus, finding a particular package and then running make install gets old. Let’s not even touch CVSup. If you know what CVSup is, you probably have distant memories of what it was like to configure it for the first time. Not that configuring CVSup is difficult, but I can think of a few dozen other things to spend my time on than trying to remember what directory the example configuration files are in, where they should be, what temporary directories to add, and what command to run. It’s been simplified since the dark ages, mind you, but it’s not a journey I’d like to repeat except for antiquated installs. (And antiquated installs are always an exciting exercise in history!)

My favorite tools for managing ports are things like portupgrade and portsearch. The former, portupgrade has something of a misleading name, and it can be used to install packages as well as upgrade them. Some of the ports tools are binaries, some are Ruby scripts, and other still can be a collection of simple shell scripts. Don’t be surprised if building one of these tools pulls in other dependencies–it needs them!

Installing portupgrade

The first thing I usually do on my FreeBSD systems is install portupgrade. It simply makes life easier whenever I have to upgrade or install new packages without hunting down where they live in ports.

Installing portupgrade is easy, here’s what you do:

Change to portupgrade‘s directory under ports:
# cd /usr/ports/ports-mgmt/portupgrade

Build it and install it:
# make install clean

If the package database requires fixing, follow the instructions you are provided. Always remember this: If you’re ever asked to run pkgdb -F, don’t wait; if you wait, the package database will grow increasingly out of sync from the other packages on your system, it’ll be more painful to update it, and you run the risk of portupgrade failing to track and install dependencies (unlikely, but it could happen).

Installing Other Packages

Now that you have portupgrade installed, you can use it to install other packages. portupgrade is a collection of upgrade/installation scripts and includes another runnable called portinstall. Now that’s truth in advertising.

This may disappoint some of you ksh fans out there. I don’t like Korn–and that goes for both the band and the shell. I tend to install bash; it’s better than csh (which can make you go bald) and I feel it’s an implementation more in the spirit of sh. Installing bash via portinstall is simple. No, really:

# portinstall bash

(This is where you wait a little while.)

Once bash is installed, you can use vipw or chsh to change your shells where appropriate (I always change the default for my user and root to bash). Bear in mind that bash isn’t located under /bin/bash as it is with most Linux distributions. You’ll either need to create a symlink to it (ln -s /usr/local/bin/bash /bin/bash) or remember that it’s located under /usr/local/bin and make your changes where appropriate. I tend to do both: I create a symlink under /bin/bash for naive scripts that expect it to reside there and change my shells to point to /usr/local/bin/bash.

There’s a few other packages you might find useful:

  • portaudit – Maintains a database of security flaws in ports. portaudit will prohibit you from using portinstall to install a package affected by an unresolved exploit. If you install this and want to install a port affected by an exploit, you’ll need to use portinstall -f to force the install.
  • portless – Similar to less, except that it displays the port description. Use this if you know the name of a port but haven’t any idea what it does.
  • portsearch – Searches ports for a specific port. This is very handy, but it requires some effort to get working–more on this later.
  • portsnap – An easier way to update your ports collection than via CVSup. You don’t normally need to install this as it comes with modern FreeBSD distributions pre-installed. You do have to do a little work to get this started–more on that later, too.
  • Updating Ports

    There’s little point in maintaining a ports collection if you don’t expect to keep it updated. Thankfully, modern FreeBSD distributions come with a handy utility that makes updating ports a snap–literally. It’s called portsnap and requires two commands to get it working for the first time:

    First, fetch a new snapshot of the ports collection:
    # portsnap fetch

    Then install it:
    # portsnap extract

    In the future, whenever you want to update your ports collection, simply run:

    # portsnap fetch
    # portsnap update

    That’s it!

    Now, you might be wondering why CVSup is still around when portsnap is so much easier to use. There isn’t much of a persuasive argument either way. portsnap, for instance, only updates your ports collection from a snapshot. CVSup updates your ports collection against a CVS repository. In theory, the latter practice using CVSup is more likely to yield a more recently updated version of ports; however, in practice, most FreeBSD CVS mirrors don’t update their own repository more often than once every four hours. The portsnap snapshot in this sense is probably updated nearly as frequently as most CVS mirrors.

    The one compelling point I would like to raise about portsnap is its security. It uses key-based authentication to reduce the chances of your ports update being altered while in transit.

    Read more about Portsnap here!

    Search Ports

    Gentoo’s portage has a handy and intuitive mechanism to search for a specific port via the emerge --search facility. In FreeBSD, there are at least three different methods to search for a port of varying difficulty. My favorite method is to use portsearch. I won’t talk about the others here. If you’re curious and wish to investigate them, read about them from the handbook.

    Installing portsearch is just as easy as everything we’ve covered thusfar:

    # portinstall portsearch

    However, once you’ve installed portsearch, it needs to know more about the packages and ports available on your system. To create and update the portsearch database, run:

    # portsearch -u

    This will take a while! Once it’s completed, searching for a specific port is almost mindlessly easy:

    # portsearch -n PORT_NAME

    Where PORT_NAME is the name of the port you’re looking for. The name doesn’t have to be exact nor is it case-sensitive, it simply has to match a fragment of the port name. For example, running:

    # portsearch -n glu

    Will return results for libGLU-7.0.3, glunarclock-0.32.4_7, and many others.

    Other Tips

    Using portinstall or portupgrade to add new, large packages to your system, you might be somewhat disgruntled to learn that it will ask for port configuration options sequentially as the ports are installed. This can be especially annoying if you have 100+ ports to install and portinstall stops after each to ask you to select which options you wish to include in the build. Thankfully, there is a feature to force portupgrade/portinstall to ask you all configuration-related questions upfront, prior to the build:

    # portinstall -C PORT_NAME

    -C forces portinstall (and portupgrade–they’re essentially the same thing) to prompt you to provide all of the package choices immediately before anything builds. This can save a lot of time if you’re building something large like KDE or Gnome.

    Conclusion

    FreeBSD is a wonderful operating system and much of its design has inspired other projects like Gentoo to include source-based package systems in their distribution. It is a real Unix, so for many people with a GNU/Linux background, FreeBSD may seem archaic in design and implementation. To me, it makes far more sense than distributions like Debian or Slackware. FreeBSD just fits. I suppose that’s why I like Gentoo so much–it’s effectively the BSD of Linux distros!

    Nevertheless, if you’re a fan of open source and actually like building things from scratch, FreeBSD is something you should try if you haven’t had any exposure to it. I used it for about four years prior to switching over to Gentoo (and I used OpenBSD before then), but FreeBSD is so much better now that I’m thinking of switching back. If you don’t like building packages from scratch, never fear: FreeBSD has a hugely robust package system that doesn’t just stop at ports; you can find binary distributions of KDE, Gnome, and dozens of other large packages on FreeBSD’s various mirror sites. I happen to like customizing my install, so building things from source is something I seldom give a second thought to.

    In short, FreeBSD can do nearly anything you want it to. It can’t run on your toaster, though. For that, you might want to look into NetBSD.

    Pages: 1 2

***

Leave a comment

Valid tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>