It's the only place our pkgsrc stuff is documented; calling it obsolete will confuse...
[ikiwiki.git] / docs / howtos / HowToPkgsrc.mdwn
0e759494 1# pkgsrc on DragonFly
b790f880 2
70d69e8b 3DragonFly uses a specially crafted Makefile in /usr and a git mirror
4of the official pkgsrc repository to make pkgsrc distribution more user-friendly.
226e0836 5
6The basics of the pkgsrc system can be found in NetBSD's [Pkgsrc Guide](, and can be considered the canonical resource.
cf1e9a79 8
fbfe8925 9[[!toc levels=3 ]]
0e759494 10
11## Overview
cf1e9a79 12
13### History
670d4043 14[Pkgsrc]( is a packaging system that was originally created for NetBSD. It has been ported to DragonFly, along with other operating systems. Pkgsrc is very similar to FreeBSD's ports mechanism.
b790f880 15
cf1e9a79 16### Overview
18If you have used a UNIX® system before you will know that the typical procedure for installing third party software goes something like this:
20 1. Download the software, which might be distributed in source code format, or as a binary.
22 1. Unpack the software from its distribution format (typically a tarball compressed with [compress(1)](, [gzip(1)](, or [bzip2(1)](
24 1. Locate the documentation (perhaps an `INSTALL` or `README` file, or some files in a `doc/` subdirectory) and read up on how to install the software.
26 1. If the software was distributed in source format, compile it. This may involve editing a `Makefile`, or running a `configure` script, and other work.
28 1. Test and install the software.
2e8be716 30And that is only if everything goes well. If you are installing a software package that was not deliberately ported to DragonFly you may even have to go in and edit the code to make it work properly. Should you want to, you can continue to install software the ***traditional*** way with DragonFly. However, DragonFly provides technology from NetBSD, which can save you a lot of effort: pkgsrc. At the time of writing, over 10,000 third party applications have been made available in this way.
cf1e9a79 31
28a42a9d 32For any given application, the DragonFly binary package for that application is a single file which you must download. The package contains pre-compiled copies of all the commands for the application, as well as any configuration files or documentation. Installing a new application can be carried out with a single command.
cf1e9a79 33
34In addition the pkgsrc collection supplies a collection of files designed to automate the process of compiling an application from source code. Remember that there are a number of steps you would normally carry out if you compiled a program yourself (downloading, unpacking, patching, compiling, installing). The files that make up a pkgsrc source collection contain all the necessary information to allow the system to do this for you. You run a handful of simple commands and the source code for the application is automatically downloaded, extracted, patched, compiled, and installed for you. In fact, the pkgsrc source subsystem can also be used to generate packages which can later be manipulated with `pkg_add` and the other package management commands that will be introduced shortly.
36Pkgsrc understands ***dependencies***. Suppose you want to install an application that depends on a specific library being installed. Both the application and the library have been made available through the pkgsrc collection. If you use the `pkg_add` command or the pkgsrc subsystem to add the application, both will notice that the library has not been installed, and automatically install the library first. You might be wondering why pkgsrc® bothers with both. Binary packages and the source tree both have their own strengths, and which one you use will depend on your own preference.
38 **Binary Package Benefits**
40* A compressed package tarball is typically smaller than the compressed tarball containing the source code for the application.
42* Packages do not require any additional compilation. For large applications, such as ***Mozilla***, ***KDE***, or ***GNOME*** this can be important, particularly if you are on a slow system.
44* Packages do not require any understanding of the process involved in compiling software on DragonFly.
47**Pkgsrc source Benefits**
50* Binary packages are normally compiled with conservative options, because they have to run on the maximum number of systems. By installing from the source, you can tweak the compilation options to (for example) generate code that is specific to a Pentium IV or Athlon processor.
52* Some applications have compile time options relating to what they can and cannot do. For example, <i>Apache</i> can be configured with a wide variety of different built-in options. By building from the source you do not have to accept the default options, and can set them yourself. In some cases, multiple packages will exist for the same application to specify certain settings. For example, <i>vim</i> is available as a `vim` package and a `vim-gtk` package, depending on whether you have installed an X11 server. This sort of rough tweaking is possible with packages, but rapidly becomes impossible if an application has more than one or two different compile time options.
54* The licensing conditions of some software distributions forbid binary distribution. They must be distributed as source code.
56* Some people do not trust binary distributions. With source code, it is possible to check for any vulnerabilities built into the program before installing it to an otherwise secure system. Few people perform this much review, however.
58* If you have local patches, you will need the source in order to apply them.
60* Some people like having code around, so they can read it if they get bored, hack it, borrow from it (license permitting, of course), and so on.
62To keep track of updated pkgsrc releases subscribe to the [NetBSD pkgsrc users mailing list]( and the [NetBSD pkgsrc users mailing list]( It's also useful to watch the [DragonFly User related mailing list]( as errors with pkgsrc on DragonFly should be reported there.
64 **Warning:** Before installing any application, you should check for security issues related to your application.
66Audit-packages will automatically check all installed applications for known vulnerabilities, a check will be also performed before any application build. Meanwhile, you can use the command `audit-packages -d` after you have installed some packages.
28a42a9d 68**Note:** Binary packages and source packages are effectively the same software and can be manipulated with the same pkg_* tools.
70## Installing pkgsrc
670d4043 72The basic pkgsrc tools are provided with every DragonFly system as part of installation. However, you still need to download the pkgsrc tree for building applications with these tools.
b790f880 73
bb002c6c 74Edit GITHOST in /usr/Makefile or set it as an environment variable to select a different download location, if desired. See mirrors page for available mirrors.
67c26dc0 75
104e5928 76This downloads the stable version of the pkgsrc tree. As root:
b790f880 77
b790f880 78 # cd /usr
7cbb018c 79 # make pkgsrc-create
b790f880 80
7cbb018c 81to fetch the intial pkgsrc repository from the net, or
b790f880 82
83 # cd /usr
84 # make pkgsrc-update
86to update.
104e5928 88**Note**: If your DragonFly install is not up to date, you might have ended up with an old release of the pkgsrc tree.
90 # cd /usr/pkgsrc
91 # git branch
93will show what release you are on. See Tracking the stable branch for more information.
21111be0 95### Tracking the stable branch
cf1e9a79 96
9c57941a 97There are quarterly releases of pkgsrc that are specifically designed for stability. You should in general follow these, rather than the bleeding edge pkgsrc. When a new branch is out you need to set up a local branch tracking that one. 'make pkgsrc-update' will not do this for you.
67c26dc0 98
4dbe296a 99To see the available remote branches:
cf1e9a79 100
ca873322 101 # cd /usr/pkgsrc
4dbe296a 102 # git pull
ca873322 103 # git branch -r
cf1e9a79 104
21111be0 105To create a local branch, tracking the remote quarterly release:
cf1e9a79 106
ca873322 107 # cd /usr/pkgsrc
108 # git branch pkgsrc-2010Q4 origin/pkgsrc-2010Q4
cf1e9a79 109
104e5928 110Branch naming format is 'pkgsrc-YYYYQX', where YYYY is the year and QX is quarters 1-4 of the year. Check []( to see the name of the latest stable branch.
cf1e9a79 111
21111be0 112After adding a new branch, it can be downloaded with:
cf1e9a79 113
ca873322 114 # cd /usr/pkgsrc
115 # git checkout pkgsrc-2010Q4
116 # git pull
cf1e9a79 117
a9f482bf 118## Dealing with pkgsrc packages
cf1e9a79 119
a9f482bf 120The following section explains how to find, install and remove pkgsrc packages.
122### Finding Your Application
cf1e9a79 123
a9f482bf 124Before you can install any applications you need to know what you want, and what the application is called. DragonFly's list of available applications is growing all the time. Fortunately, there are a number of ways to find what you want:
cf1e9a79 125
a9f482bf 126Since DragonFly 1.11 [pkg_search(1)]( is included in the base system. [pkg_search(1)]( searches an already installed pkgsrc INDEX for for a given package name. If pkgsrc is not installed or the INDEX file is missing, it fetches the [pkg_summary(5)]( file.
cf1e9a79 127
128 # pkg_search fvwm
129 fvwm-2.4.20nb1 Newer version of X11 Virtual window manager
130 fvwm-2.5.24 Development version of X11 Virtual window manager
131 fvwm-themes-0.6.2nb8 Configuration framework for fvwm2 with samples
132 fvwm-wharf-1.0nb1 Copy of AfterStep's Wharf compatible with fvwm2
133 fvwm1-1.24rnb1 Virtual window manager for X
135 # pkg_search -v fvwm-2.5
136 Name : fvwm-2.5.24-50
137 Dir : wm/fvwm-devel
138 Desc : Development version of X11 Virtual window manager
139 URL : any
140 Deps : perl>#5.0 gettext-lib>0.14.5 [...]
142Its also possible to issue the command
144 # cd /usr/pkgsrc/
145 # bmake search key='package you are looking for'
a9f482bf 147from the `/usr/pkgsrc` directory.
cf1e9a79 148
a9f482bf 149It's also possible to browse website that show all the available pkgsrc packages, such as []( .
1cd7a23a 150
28a42a9d 151### Installing applications
153Downloading a binary package is almost always faster than building from source, but not all programs in pkgsrc can be redistributed as a binary. In most cases, you will want to download a binary package if possible, and otherwise build from source if it's not available.
155The `bin-install` target on DragonFly (with pkgsrc from 2011/02/07 and later) will do just that:
157 # cd /usr/pkgsrc/misc/screen
158 # bmake bin-install clean
160This will download and install the appropriate `screen` binary package if it exists, and try building from source if it can't complete the download.
162### Installing applications, source only
1cd7a23a 163
a9f482bf 164Packages are built by going into the appropriate directory and issuing `bmake install clean`. For example, to build the *screen* package you need to issue the following commands.
b790f880 165
166 # cd /usr/pkgsrc/misc/screen
167 # bmake install clean
670d4043 169To find out the options that can affect how a program is built:
b790f880 170
171 # bmake show-options
670d4043 173To change options:
b790f880 174
175 # bmake PKG_OPTIONS.<package_name>="-option1 option2" install clean
670d4043 177Listing an option enables it. Listing an option with a "-" before it disables the option.
b790f880 178
a9f482bf 179To make these option changes permanent for every future build or upgrade of this package, put a similar line in `/usr/pkg/etc/mk.conf`:
181 . PKG_OPTIONS.<package_name>=-option1 option2
28a42a9d 183### Installing applications, binary only
b790f880 184
a9f482bf 185Binary packages can be installed using *pkg_radd*:
b790f880 186
670d4043 187 # pkg_radd screen
b790f880 188
2e8be716 189This program works by setting the `PKG_PATH` environment variable to the appropriate path for the operating system and architecture to a remote repository of binary packages, and then using *pkg_add* to get packages. This will install most packages, but will not upgrade packages that are already installed.
b790f880 190
2e8be716 191You can manually set `BINPKG_BASE` and use *pkg_add* to get the same effect, using a different server.
b790f880 192
2e8be716 193 # setenv BINPKG_BASE
670d4043 194 # pkg_add screen
b790f880 195
28a42a9d 196
2e8be716 197#### Issues with pre-built packages
b790f880 198
2e8be716 199* The default remote repository for binary packages tracks quarterly pkgsrc releases, so your local install of pkgsrc should be the same quarterly release.
200* Some packages are not licensed for distribution in binary form, so they may be able to build on DragonFly but won't be available with *pkg_radd*. If it fails, try going to that package's directory and install the package manually as described above.
201* If you upgrade to an new DEVELOPMENT version of DragonFly very early (i.e. shortly after the branch), it might be possible that *pkg_radd* fails to install packages. This is due the fact, that it takes some time to built binary packages and thus, there are no binary packages available on the mirrors yet. Usually you'll see an announcement on the lists once the first packages for DEVELOPMENT are ready.
b790f880 202
b790f880 203
0e759494 204### List all installed applications
670d4043 205
206To obtain a list of all the packages that are installed on your system:
b790f880 207
208 # pkg_info
2e8be716 210To see if certain packages have been installed, filter for the name of the package. This example will show all *xorg*-related packages currently installed on the system:
b790f880 211
212 # pkg_info | grep xorg
a9f482bf 214### Removing packages
b790f880 215
cf1e9a79 216If a program was installed as a package:
b790f880 217
cf1e9a79 218 # pkg_delete packagename
b790f880 219
cf1e9a79 220If a package was installed from the source files, you can also change to the directory they were installed from and issue the command:
b790f880 221
cf1e9a79 222 # bmake deinstall
b790f880 223
c1e30046 224Note that these methods are effectively interchangeable. Either will work whether the package was originally installed from source or binary.
a9f482bf 226#### Remove associated files needed for building a package
b790f880 227
cf1e9a79 228To remove the work file from building a package, and the package's dependencies:
b790f880 229
cf1e9a79 230 # bmake clean clean-depends
670d4043 231
cf1e9a79 232This can be combined with other steps:
b790f880 233
cf1e9a79 234 # bmake install clean clean-depends
b790f880 235
cf1e9a79 236## Upgrading packages
b790f880 237
30ceb822 238There's a number of ways to upgrade pkgsrc; some of these are built in and some are packages installable with pkgsrc. This list is not necessarily comprehensive.
240### Update pkgsrc system packages
242**Note**: Sometimes basic pkgsrc tools; *bmake*, *pkg_install* and *bootstrap-mk-files* need to be upgraded. However, they can't be deleted and replaced since you need that tool to accomplish replacement. The solution is to build a separate package before deletion, and install that package.
244 # cd /usr/pkgsrc/devel/bmake
2822e5b0 245 or
b734238f 246 # cd /usr/pkgsrc/pkgtools/pkg_install
2822e5b0 247 or
b734238f 248 # cd /usr/pkgsrc/pkgtools/bootstrap-mk-files
2822e5b0 249
30ceb822 250 # env USE_DESTDIR=yes bmake package
251 # bmake clean-depends clean
253And go to the packages directory and install the binary package with
255 # cd /usr/pkgsrc/packages/All
256 # pkg_add -u <pkg_name> (i.e. the name of the .tgz file).
b790f880 258
f5e66381 259### bmake replace
260Performed in the `/usr/pkgsrc` directory that correlates with the installed package, the software is first built and then replaced.
262 # cd /usr/pkgsrc/chat/ircII
263 # bmake replace
cf1e9a79 265### pkg_rolling-replace
b790f880 266
30ceb822 267*pkg_rolling-replace* replaces packages one by one and you can use it for a better way of package management. Actually it does `bmake replace` on one package at a time, sorting the packages being replaced according to their interdependencies, which avoids most duplicate rebuilds. Once *pkg_rolling-replace* is installed you can update the packages through the following steps.
b790f880 268
cf1e9a79 269 # cd /usr && make pkgsrc-update
270 # pkg_rolling-replace -u
b790f880 271
cf1e9a79 272### pkgin
b790f880 273
a9f482bf 274Downloads and installs binary packages. Check the [[mirrors]] page for sites carrying binary packages to use with pkgin. You can run the following commands to get the packages updated. This assumes that *pkgin* is already configured. Please consult the documentation and the man page on how to do so.
fa94fcaa 275
cf1e9a79 276 # pkgin update
277 # pkgin full-upgrade
fa94fcaa 278
cf1e9a79 279### pkg_chk
b790f880 280
a9f482bf 281It updates packages by removing them and rebuilding them. Warning: programs are unavailable until a rebuild finishes. If they don't rebuild, it won't work. *pkg_chk* requires a few steps in order to work correctly. They are listed here.
b790f880 282
a9f482bf 283 # pkg_chk -g # make initial list of installed packages
cf1e9a79 284 # pkg_chk -r # remove all packages that are not up to date and packages that depend on them
285 # pkg_chk -a # install all missing packages (use binary packages, this is the default)
286 # pkg_chk -as # install all missing packages (build from source)
b790f880 287
cf1e9a79 288The above process removes all packages at once and installs the missing packages one by one. This can cause longer disruption of services when the removed package has to wait a long time for its turn to get installed.
b790f880 289
cf1e9a79 290### pkg_add -u
b790f880 291
cf1e9a79 292Point at a local or online binary archive location to download and update packages.
b790f880 293
d3b97f72 294### rpkgmanager
849487e3 296This requires that you've set up rpkgmanager first. Read more about rpkgmanager [[here|docs/howtos/rpkgmanager/]].
d3b97f72 297
849487e3 298 # yes | rpkgmanager.rb
d3b97f72 299
a9f482bf 300## Start pkgsrc applications on system startup
302Packages often install rc.d scripts to control software running on startup. To specify where the rc.d scripts from the installed packages should go, add the following lines to your `/usr/pkg/etc/mk.conf` file:
b790f880 303
1cd7a23a 304 RCD_SCRIPTS_DIR=/etc/rc.d
b790f880 306
0e759494 307This option can be set in the environment to activate it for binary packages. These packages will still have to be enabled in `/etc/rc.conf/` to run at boot. If these options aren't set, the rc file will be placed in `/usr/pkg/share/examples/rc.d/` and will need to be manually copied over to `/etc/rc.d`.
a9f482bf 308
309Many other options can be set in this file; see `/usr/pkgsrc/mk/defaults/mk.conf` for examples.
311## Miscellaneous topics
313### Post-installation Activities
315After installing a new application you will normally want to read any documentation it may have included, edit any configuration files that are required, ensure that the application starts at boot time (if it is a daemon), and so on.
316 The exact steps you need to take to configure each application will obviously be different. However, if you have just installed a new application and are wondering *What now?* These tips might help:
318Use [pkg_info(1)]( to find out which files were installed, and where. For example, if you have just installed Foo_Package version 1.0.0, then this command
320 # pkg_info -L foopackage-1.0.0 | less
322will show all the files installed by the package. Pay special attention to files in `man/` directories, which will be manual pages, `etc/` directories, which will be configuration files, and `doc/`, which will be more comprehensive documentation. If you are not sure which version of the application was just installed, a command like this
324 # pkg_info | grep -i foopackage
2e8be716 326will find all the installed packages that have *foopackage* in the package name. Replace *foopackage* in your command line as necessary.
a9f482bf 327
328Once you have identified where the application's manual pages have been installed, review them using [man(1)]( Similarly, look over the sample configuration files, and any additional documentation that may have been provided. If the application has a web site, check it for additional documentation, frequently asked questions, and so forth. If you are not sure of the web site address it may be listed in the output from
330 # pkg_info foopackage-1.0.0
a9f482bf 332A `WWW:` line, if present, should provide a URL for the application's web site.
334### Dealing with Broken Packages
336If you come across a package that does not work for you, there are a few things you can do, including:
338 1. Fix it! The [pkgsrc Guide]( includes detailed information on the ***pkgsrc®*** infrastructure so that you can fix the occasional broken package or even submit your own!
340 1. Send email to the maintainer of the package first. Type `bmake maintainer` or read the `Makefile` to find the maintainer's email address. Remember to include the name and version of the port (send the `$NetBSD:` line from the `Makefile`) and the output leading up to the error when you email the maintainer. If you do not get a response from the maintainer, you can try [users]( .
b790f880 341
a9f482bf 342 1. Grab a pre-built package from an [[mirror|mirrors]] site near you.
07601fb9 343
a9f482bf 344### What is WIP?
b790f880 345
40741f0e 346Packages that can be built within the pkgsrc framework but are not yet necessarily ready for production use can be found in []( These packages need to be downloaded separately; check the website for details. Packages in this collection are in development and may not build successfully.
b790f880 347
a9f482bf 348### Links
b790f880 349
83f36747 350* More information: The pkgsrc guide [](
b790f880 351
83f36747 352* Web interface for searching packages: [](
b790f880 353
83f36747 354* Ways to upgrade packages [](
b5456305 355
1cd7a23a 356* To search and/or report bugs against packages in pkgsrc, look at []( - use category 'pkg'.
b790f880 357
1cd7a23a 358* The #pkgsrc IRC channel on Freenode
b790f880 359
1cd7a23a 360* The #dragonflybsd IRC channel on EFnet