Bookmark and Share

Intro to pkgsrc

pkgsrc is a package management system for Unix-like operating systems. It supports OS X. Therefore, it's an viable alternative to Homebrew and Macports, which are the most widely used package management systems on Mac computers. I originally became interested in trying pkgsrc because some softwares I would like to install are not available via Homebrew.

Install, configure, manage pkgsrc and software packages in it

Installing and configuring pkgsrc on macOS (64-bit, version 10.9 or later)

The following is based on https://pkgsrc.joyent.com/install-on-osx/.

  • Copy and paste the lines below to install the 64-bit 10.9+ set.

      BOOTSTRAP_TAR="bootstrap-trunk-x86_64-20170205.tar.gz"
      BOOTSTRAP_SHA="177e0be390b57ef9d7f61511a8169268000693df"
    
  • Download the bootstrap kit to the current directory.

      curl -O https://pkgsrc.joyent.com/packages/Darwin/bootstrap/${BOOTSTRAP_TAR}
    
  • Verify the SHA1 checksum.

      echo "${BOOTSTRAP_SHA}  ${BOOTSTRAP_TAR}" >check-shasum
      shasum -c check-shasum
    
  • Verify PGP signature. This step is optional, and requires gpg.

      curl -O https://pkgsrc.joyent.com/packages/Darwin/bootstrap/${BOOTSTRAP_TAR}.asc
      gpg --recv-keys 0x1F32A9AD
      gpg --verify ${BOOTSTRAP_TAR}{.asc,}
    
  • Install bootstrap kit to /opt/pkg

      sudo tar -zxpf ${BOOTSTRAP_TAR} -C /
    
  • Reload PATH/MANPATH (pkgsrc installs /etc/paths.d/10-pkgsrc for new sessions)

      eval $(/usr/libexec/path_helper)
    

Installing pkgsrc on Ubuntu Linux

TODO

Installing softwares

There are three ways of installing softwares using pkgsrc:

  1. The most typical method is to build a software from source files, a.k.a. "bootstrapping";
  2. Another possibly easier method is to install and uninstall pre-built softwares using commands pkg_add and pkg_delete, respectively;
  3. Install softwares using the high-level tool pkgin. It's the facsimile of Ubuntu and Debian Linux's apt-get in pkgsrc.

Use pkgsrc to install softwares

Use pkgsrc to install some softwares that Homebrew can't.

  • Refresh the pkgin database with the latest version

      $ sudo pkgin -y update
    
  • Search for a package. Regular expressions are supported.

      $ pkgin search "^ffmpeg[0-9]$"
      ffmpeg3-3.0.1   Decoding, encoding and streaming software (v3.x)
      ffmpeg2-2.8.6   Decoding, encoding and streaming software (v2.x)
      ffmpeg1-1.2.12  Decoding, encoding and streaming software (v1.x)
    
  • Install a package without prompting

      $ sudo pkgin -y install ffmpeg3
    
  • List all available packages

      $ pkgin avail
    
  • Upgrade all out-of-date packages

      $ sudo pkgin -y full-upgrade
    
  • Remove a package

      $ sudo pkgin -y remove ffmpeg2
    
  • Automatically remove orphaned dependencies

      $ sudo pkgin -y autoremove
    

Use pkg_* tools to manage packages

  • See what packages are installed.

      $ pkg_info
    
  • See what package a file belongs to.

      $ pkg_info -Fe /opt/pkg/bin/node
      nodejs-4.4.3
    
  • List the contents of a package.

      $ pkg_info -qL nodejs
      /opt/pkg/bin/node
      /opt/pkg/bin/npm
      [...]
    
  • Perform an audit of all currently installed packages.

      $ sudo pkg_admin fetch-pkg-vulnerabilities
      $ pkg_admin audit
      Package jasper-1.900.1nb11 has a integer-overflow vulnerability, see http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-3520
      Package samba-3.6.25nb3 has a privilege-escalation vulnerability, see https://www.samba.org/samba/security/CVE-2015-5299.html
      Package tiff-4.0.6 has a arbitrary-memory-access vulnerability, see http://www.securityfocus.com/archive/1/537205
      [...]
    
  • Create a binary package from some metadata files and package directory.

      $ pkg_create -B build-info -c comment -d description -f packlist -I /opt/pkg -p files/ -U foo-1.0.tgz
    

Configuration file mk.conf for "bootstrapping"

After running

pkgsrc/bootstrap

it creates a example configuration file ../pkgsrc/bootstrap/work/mk.conf.example:

# Example /usr/pkg/etc/mk.conf file produced by bootstrap-pkgsrc
# Sat Feb  7 20:20:18 PST 2015

.ifdef BSD_PKG_MK   # begin pkgsrc settings

PKGSRC_COMPILER=    clang
CC=         clang
CXX=            clang++
CPP=            ${CC} -E
CLANGBASE=      /usr

PKG_DBDIR=      /var/db/pkg
LOCALBASE=      /usr/pkg
VARBASE=        /var
PKG_TOOLS_BIN=      /usr/pkg/sbin
PKGINFODIR=     info
PKGMANDIR=      man

TOOLS_PLATFORM.awk?=        /usr/pkg/bin/nawk
TOOLS_PLATFORM.sed?=        /usr/pkg/bin/nbsed

.endif          # end pkgsrc settings

Here is a version that is customized and installed at /usr/pkg/etc/mk.conf:

.ifdef BSD_PKG_MK       # begin pkgsrc settings

ABI=                    64
PKGSRC_COMPILER=        clang
CC=                     clang
CXX=                    clang++
CPP=                    ${CC} -E
CLANGBASE=              /usr

PKG_DBDIR=              /usr/pkg/.pkgdb
LOCALBASE=              /usr/pkg
VARBASE=                /var
PKG_TOOLS_BIN=          /usr/pkg/sbin
PKGINFODIR=             info
PKGMANDIR=              man

TOOLS_PLATFORM.awk?=    /usr/pkg/bin/nawk
TOOLS_PLATFORM.sed?=    /usr/pkg/bin/nbsed

MULTILIB_SUPPORTED=     no

PREFER.openssl=         pkgsrc

X11_TYPE=               native
X11BASE=                /opt/X11

.if !empty(PKGPATH:Mmail/mutt-devel)
PKG_OPTIONS.mutt+=      mutt-hcache mutt-smtp ncursesw sasl
.endif

.endif                  # end pkgsrc settings

Uninstalling pkgsrc and softwares installed by it

Delete the following directories:

sudo rm -rf /usr/pkg
sudo rm -rf /var/db/pkg*

and possibly also the source files if you used the first method:

sudo rm -rf /path/to/pkgsrc

References

blog comments powered by Disqus