7 [Pkgsrc](http://www.pkgsrc.org) 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.
11 If you have used a UNIX® system before you will know that the typical procedure for installing third party software goes something like this:
13 1. Download the software, which might be distributed in source code format, or as a binary.
15 1. Unpack the software from its distribution format (typically a tarball compressed with [compress(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=compress§ion1), [gzip(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=gzip§ion=1), or [bzip2(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=bzip2§ion=1)).
17 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.
19 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.
21 1. Test and install the software.
23 And 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 8,000 third party applications have been made available in this way.
25 For 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. A downloaded package file can be manipulated with DragonFly package management commands, such as [pkg_radd(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=pkg_add§ion1), [pkg_delete(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=pkg_delete§ion=1), [pkg_info(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=pkg_info§ion=1), and so on. Installing a new application can be carried out with a single command.
29 In 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.
31 Pkgsrc 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.
33 **Binary Package Benefits**
35 * A compressed package tarball is typically smaller than the compressed tarball containing the source code for the application.
37 * 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.
39 * Packages do not require any understanding of the process involved in compiling software on DragonFly.
42 **Pkgsrc source Benefits**
45 * 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.
47 * 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.
49 * The licensing conditions of some software distributions forbid binary distribution. They must be distributed as source code.
51 * 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.
53 * If you have local patches, you will need the source in order to apply them.
55 * 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.
57 To keep track of updated pkgsrc releases subscribe to the [NetBSD pkgsrc users mailing list](http://www.netbsd.org/MailingLists/pkgsrc-users) and the [NetBSD pkgsrc users mailing list](http://www.netbsd.org/MailingLists/tech-pkgsrc). It's also useful to watch the [DragonFly User related mailing list](http://leaf.dragonflybsd.org/mailarchive/) as errors with pkgsrc on DragonFly should be reported there.
59 **Warning:** Before installing any application, you should check http://www.pkgsrc.org/ for security issues related to your application.
61 Audit-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.
65 The 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.
72 to fetch the intial pkgsrc repository from the net, or
79 Edit /usr/Makefile to select a different download location, if desired.
81 This downloads the absolute most recent version of pkgsrc. In a production environment, you may want a more stable release. Check the section below for more details.
83 ### Tracking the stable branch
85 There are quarterly releases of pkgsrc that are specifically designed for stability. You should in general follow the latest branch, rather than bleeding edge pkgsrc.
87 To see the available branches:
92 To switch to a recent branch:
95 git branch pkgsrc-2010Q3 origin/pkgsrc-2010Q3
97 Branch naming format is 'pkgsrc-YYYYQX', where YYYY is the year and QX is quarters 1-4 of the year. Check [pkgsrc.org](http://www.pkgsrc.org/) to see the name of the most recently released branch.
99 After switching to a new branch, it can be downloaded with:
105 ## Finding Your Application
107 Before 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:
109 Since DragonFly 1.11 [pkg_search(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=pkg_search§ion1) is included in the base system. [pkg_search(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=pkg_search§ion=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)](http://leaf.dragonflybsd.org/cgi/web-man?command=pkg_summary§ion=5) file.
111 **Example. Find a Package**
114 fvwm-2.4.20nb1 Newer version of X11 Virtual window manager
115 fvwm-2.5.24 Development version of X11 Virtual window manager
116 fvwm-themes-0.6.2nb8 Configuration framework for fvwm2 with samples
117 fvwm-wharf-1.0nb1 Copy of AfterStep's Wharf compatible with fvwm2
118 fvwm1-1.24rnb1 Virtual window manager for X
120 # pkg_search -v fvwm-2.5
121 Name : fvwm-2.5.24-50
123 Desc : Development version of X11 Virtual window manager
125 Deps : perl>#5.0 gettext-lib>0.14.5 [...]
127 Its also possible to issue the command
130 # bmake search key='package you are looking for'
132 from the /usr/pkgsrc directory.
134 It's also possible to browse website that show all the available pkgsrc packages, such as [http://pkgsrc.se/](http://pkgsrc.se)
136 ## Installing packages from source
138 Packages 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.
140 # cd /usr/pkgsrc/misc/screen
141 # bmake install clean
143 To find out the options that can affect how a program is built:
149 # bmake PKG_OPTIONS.<package_name>="-option1 option2" install clean
151 Listing an option enables it. Listing an option with a "-" before it disables the option.
153 To make these option changes permanent for every future build or upgrade of this package, put a similar line in /usr/pkg/etc/mk.conf:
155 . PKG_OPTIONS.<package_name>=-option1 option2
157 ## Installing pre-built packages
159 Binary packages can be installed using pkg_radd:
163 This program works by setting the PKG_PATH enviroment 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.
165 You can manually set PKG_PATH and use pkg_add to get the same effect, using a different server.
167 # setenv PKG_PATH http://avalon.dragonflybsd.org/packages/i386/DragonFly-2.7/stable
170 *Note:* The above URL is for the DragonFly-2.7 on i386. Adjust the file path to match your installation and what's available on the server.
172 This will install most packages, but will not upgrade packages that are already installed.
174 ***Note:*** that the default remote repository for binary packages tracks quarterly pkgsrc releases, so your local install of pkgsrc should be the same quarterly release.
176 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 pkg_radd fails, try going to that package's directory in /usr/pkgsrc and using 'bmake install clean'.
178 ### Dealing with different package versions
180 Due to the fact that the official packages are only build for the RELEASE-Version of DragonFly, it is possible that you see a warning when installing binary packages on a DEVELOPMENT-version of DragonFly. The warning could look like this:
182 pkg_add: Warning: package `vim-gtk2-7.1.116.tgz' was built for a different version of the OS:
183 pkg_add: DragonFly/i386 1.10.1 (pkg) vs. DragonFly/i386 1.11.0 (this host)
185 You can safely ignore this warning. Normally all packages build for RELEASE run fine on DEVELOPMENT unless a major API-breakage was introduced. In this case you would see a message from the developers on the appropriate mailing list.
187 ## List all installed packages
189 To obtain a list of all the packages that are installed on your system:
193 To 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:
195 # pkg_info | grep xorg
199 If a program was installed as a package:
201 # pkg_delete packagename
203 If a package was installed from the source files, you can also change to the directory they were installed from and issue the command:
207 ### Remove associated files needed for building a package
209 To remove the work file from building a package, and the package's dependencies:
211 # bmake clean clean-depends
213 This can be combined with other steps:
215 # bmake install clean clean-depends
217 ## Upgrading packages
219 There'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. Be sure to read the note about upgrading pkgsrc system packages at the end of this subsection!
221 ### pkg_rolling-replace
223 *pkg_rolling-replace* replaces packages one by one and one can use it for a better way of package management. Actually it does `make 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.
225 # cd /usr && make pkgsrc-update
226 # pkg_rolling-replace -u
230 Downloads 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.
237 It 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.
239 # pkg_chk -g # make initial list of installed packages
240 # pkg_chk -r # remove all packages that are not up to date and packages that depend on them
241 # pkg_chk -a # install all missing packages (use binary packages, this is the default)
242 # pkg_chk -as # install all missing packages (build from source)
244 The 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.
248 Performed in the /usr/pkgsrc directory that correlates with the installed package, the software is deleted and rebuilt. The same warning applies as with pkg_chk.
252 Point at a local or online binary archive location to download and update packages.
254 #### Update pkgsrc system packages
256 **Note**: Sometimes, basic pkgsrc tools, like bmake or pkg_install, 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. Inside the packages directory (/usr/pkgsrc/devel/bmake in this case)
258 # env USE_DESTDIR=full bmake package
259 # bmake clean-depends clean
261 And go to the packages directory and install the binary package with
263 # pkg_add -u <pkg_name> (i.e. the name of the .tgz file).
264 # bmake replace USE_DESTDIR=yes
265 ## Additional /usr/pkg/etc/mk.conf notes
267 Packages often install rc.d scripts to control software running on startup. To specify where the rc.d scripts from the installed packages should go:
269 RCD_SCRIPTS_DIR=/etc/rc.d
272 This option can be set in the environment to activate it for binary packages. These packages will still have to be enabled in 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.
274 Many other options can be set in this file; see /usr/pkgsrc/mk/defaults/mk.conf for examples.
278 Packages that can be built within the pkgsrc framework but are not yet necessarily ready for production use can be found in [http://pkgsrc-wip.sourceforge.net](http://pkgsrc-wip.sourceforge.net). These packages need to be downloaded separately; check the website for details. Packages in this collection are in development and may not build successfully.
282 * [http://www.netbsd.org/Documentation/pkgsrc/](http://www.netbsd.org/Documentation/pkgsrc/)
284 * [http://www.pkgsrc.se](http://www.pkgsrc.se)
286 * [http://wiki-static.aydogan.net/How_to_upgrade_packages](http://wiki-static.aydogan.net/How_to_upgrade_packages)
288 * To search and/or report bugs against packages in pkgsrc, look at [http://www.netbsd.org/support/send-pr.html](http://www.netbsd.org/support/send-pr.html) - use category 'pkg'.
290 * [http://pkgsrc-wip.sourceforge.net](http://pkgsrc-wip.sourceforge.net), **w**ork **i**n **p**rogress packages not yet in official pkgsrc release
292 * An [in-depth explanation of pkgsrc](http://www.unixgarden.com/index.php/administration-reseau/netbsd-s01e03-gestion-des-paquets), in French.
294 * The #pkgsrc IRC channel on Freenode
296 * The #dragonflybsd IRC channel on EFnet