confusing using of examples and literal commands in the same block fixed
[ikiwiki.git] / docs / howtos / HowToDPorts / index.mdwn
1 # DPorts and pkgng
2
3 Dports is DragonFly's own third-party software build system.  It is based on FreeBSD's Ports Collection.  Differences between ports and DPorts are intentionally kept to a minimum, both to maintain familiarity for mutual users of both operating systems and also to leverage the tremendous amount of work the FreeBSD contributors put into ports.  DPorts can and does feature ports unique to DragonFly, so it's truly a native system.
4
5 The __pkgng__ tool called "pkg" is a modern and fast binary package manager.  It was developed for FreeBSD, but PC-BSD used it in production first, followed soon after by DragonFly.  In the future, it will be the only binary package manager on FreeBSD just as it is for DPorts.
6
7 __pkgng__ is not a replacement for port management tools like `ports-mgmt/portmaster` or `ports-mgmt/portupgrade`. While `ports-mgmt/portmaster` and `ports-mgmt/portupgrade` can install third-party software from both binary packages and DPorts, __pkgng__ installs only binary packages.
8
9 ## Getting started with pkgng
10
11 DragonFly daily snapshots and Releases (starting with 3.4) come with __pkgng__ already installed.  However upgrades from earlier releases won't have it.  If the "pkg" program is missing on the system for any reason, it can be quickly bootstrapped without having to build it from source.
12
13 To bootstrap __pkgng__ from source on a pkgsrc-using system, run:
14
15     # cd /usr
16     # make dports-create
17     # rm -rf pkg  ( as in /usr/pkg )
18     # pkg upgrade
19
20 Before using consult the man page (`man pkg`) and then try things like these examples:
21
22
23     # pkg search editors
24     # pkg install vim
25
26
27 To bootstrap __pkgng__ with a download on a pkgsrc-using system, run:
28
29     # make pkg-bootstrap
30     # rehash
31     # pkg-static install -y pkg
32     # rehash
33
34 Note that this step is unnecessary for any newly installed release from DragonFly 3.4 onwards.
35
36 ## Configuring the pkgng Environment
37
38 The __pkgng__ package management system uses a package repository for most operations. The default package repository location is defined in `/usr/local/etc/pkg.conf` or the `PACKAGESITE` environment variable, which overrides the configuration file.  Additional __pkgng__ configuration options are described in pkg.conf(5).
39
40 The pkg.conf file comes preinstalled with the latest release repository pre-selected.
41
42     PACKAGESITE: http://avalon.dragonflybsd.org/dports/${ABI}/RELEASE
43
44 The RELEASE repository is static, but the LATEST repository is periodically updated.  If bleeding edge is wanted, change pkg.conf to reflect that:
45
46     PACKAGESITE: http://avalon.dragonflybsd.org/dports/${ABI}/LATEST
47
48 DragonFly users on the development branch can also use pre-built binary packages from the last release, but they will need to override the ABI in pkg.conf, e.g.:
49
50     ABI: dragonfly:3.4:x86:32  # for i386 platform
51     ABI: dragonfly:3.4:x86:64  # for x86-64 platform
52
53 There are already a few mirrors available which can be set in pkg.conf
54
55 * North America: http://avalon.dragonflybsd.org/dports/${ABI}/LATEST
56 * Europe: http://pkg.wolfpond.org/${ABI}/LATEST
57 * Europe: http://mirrors.ircam.fr/pub/DragonFlyBSD-dports/${ABI}/LATEST
58 * Europe: http://dfly.schlundtech.de/dports/${ABI}/LATEST
59
60 All the above european mirrors are IPV6-enabled.
61
62 ## Basic pkgng Operations
63
64 Usage information for __pkgng__ is available in the pkg(8) manual page, or by running `pkg` without additional arguments.
65
66 Each __pkgng__ command argument is documented in a command-specific manual page. To read the manual page for `pkg install`, for example, run either:
67
68     # pkg help install
69     # man pkg-install
70
71 ## Obtaining Information About Installed Packages with pkgng
72
73 Information about the packages installed on a system can be viewed by running `pkg info`. Similar to pkg_info(1), the package version and description for all packages will be listed.  Information about a specific package is available by running:
74
75     # pkg info packagename
76
77 For example, to see which version of __pkgng__ is installed on the system, run:
78
79     # pkg info pkg
80     pkg-1.0.12                   New generation package manager
81
82 ## Installing and Removing Packages with pkgng
83
84 In general, most DragonFly users will install binary packages by typing:
85
86     # pkg install <packagename>
87
88 For example, to install curl:
89
90     # pkg install curl
91
92     Updating repository catalogue
93     Repository catalogue is up-to-date, no need to fetch fresh copy
94     The following packages will be installed:
95     
96         Installing ca_root_nss: 3.13.5
97         Installing curl: 7.24.0
98     
99     The installation will require 4 MB more space
100     
101     1 MB to be downloaded
102     
103     Proceed with installing packages [y/N]: y
104     ca_root_nss-3.13.5.txz           100%    255KB   255.1KB/s  255.1KB/s   00:00
105     curl-7.24.0.txz                  100%   1108KB     1.1MB/s    1.1MB/s   00:00
106     Checking integrity... done
107     Installing ca_root_nss-3.13.5... done
108     Installing curl-7.24.0... done
109
110 The new package and any additional packages that were installed as dependencies can be seen in the installed packages list:
111
112     # pkg info
113     ca_root_nss-3.13.5    The root certificate bundle from the Mozilla Project
114     curl-7.24.0           Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
115     pkg-1.0.12            New generation package manager
116
117 Packages that are no longer needed can be removed with `pkg delete`. For example, if it turns out that curl is not needed after all:
118
119     # pkg delete curl
120     The following packages will be deleted:
121     
122         curl-7.24.0_1
123     
124     The deletion will free 3 MB
125     
126     Proceed with deleting packages [y/N]: y
127     Deleting curl-7.24.0_1... done
128
129 ## Upgrading Installed Packages with pkgng
130
131 Packages that are outdated can be found with `pkg version`. If a local ports tree does not exist, pkg-version(8) will use the remote repository catalogue, otherwise the local ports tree will be used to identify package versions.
132
133 Packages can be upgraded to newer versions with __pkgng__. Suppose a new version of curl has been released. The local package can be upgraded to the new version:
134
135     # pkg upgrade
136     Updating repository catalogue
137     repo.txz            100%    297KB   296.5KB/s   296.5KB/s   00:00
138     The following packages will be upgraded:
139     
140     Upgrading curl: 7.24.0 -> 7.24.0_1
141     
142     1 MB to be downloaded
143     
144     Proceed with upgrading packages [y/N]: y
145     curl-7.24.0_1.txz   100%    1108KB  1.1MB/s       1.1MB/s   00:00
146     Checking integrity... done
147     Upgrading curl from 7.24.0 to 7.24.0_1... done
148
149 ## Auditing Installed Packages with pkgng
150
151 Occasionally, software vulnerabilities may be discovered in software within DPorts. __pkgng__ includes built-in auditing. To audit the software installed on the system, type:
152
153     # pkg audit -F
154
155 # Advanced pkgng Operations
156
157 ## Automatically Removing Leaf Dependencies with pkgng
158
159 Removing a package may leave behind unnecessary dependencies, like `security/ca_root_nss` in the example above. Such packages are still installed, but nothing depends on them any more. Unneeded packages that were installed as dependencies can be automatically detected and removed:
160
161     # pkg autoremove
162     Packages to be autoremoved:
163         ca_root_nss-3.13.5
164     
165     The autoremoval will free 723 kB
166     
167     Proceed with autoremoval of packages [y/N]: y
168     Deinstalling ca_root_nss-3.13.5... done
169
170 ## Backing Up the pkgng Package Database
171
172 __pkgng__ includes its own package database backup mechanism. To manually back up the package database contents, type:
173
174     # pkg backup -d <pkgng.db>
175
176 Additionally, __pkgng__ includes a periodic(8) script to automatically back up the package database daily if `daily_backup_pkgng_enable` is set to `YES` in periodic.conf(5).   To prevent the `pkg_install` periodic script from also backing up the package database, set `daily_backup_pkgdb_enable` to `NO` in periodic.conf(5).
177
178 To restore the contents of a previous package database backup, run:
179
180     # pkg backup -r </path/to/pkgng.db>
181
182 ## Removing Stale pkgng Packages
183
184 By default, __pkgng__ stores binary packages in a cache directory as defined by `PKG_CACHEDIR` in pkg.conf(5). When upgrading packages with pkg upgrade, old versions of the upgraded packages are not automatically removed.
185
186 To remove the outdated binary packages, type:
187
188     # pkg clean
189
190 ##Modifying pkgng Package Metadata
191
192 __pkgng__ has a built-in command to update package origins. For example, if `lang/php5` was originally at version 5.3, but has been renamed to lang/php53 for the inclusion of version 5.4, the package database can be updated to deal with this. For __pkgng__, the syntax is:
193
194     # pkg set -o <category/oldport>:<category/newport>
195
196 For example, to change the package origin for the above example, type:
197
198     # pkg set -o lang/php5:lang/php53
199
200 As another example, to update lang/ruby18 to lang/ruby19, type:
201
202     # pkg set -o lang/ruby18:lang/ruby19
203
204 As a final example, to change the origin of the libglut shared libraries from graphics/libglut to graphics/freeglut, type:
205
206     # pkg set -o graphics/libglut:graphics/freeglut
207
208 _Note_: When changing package origins, in most cases it is important to reinstall packages that are dependent on the package that has had the origin changed. To force a reinstallation of dependent packages, type:
209
210     # pkg install -Rf graphics/freeglut
211
212 # Building DPorts from source
213
214 The average user will probably not build packages from source.  However, it's easy to do and it can be done even when packages have already been pre-installed on the system.  Common reasons to build from source are:
215
216 * The port is new and there's no pre-binary available yet
217 * The pre-built binaries use the default options and the user needs a package built with a different set of options
218 * Testing FreeBSD port in order to patch them and submit to DPorts
219 * The user just prefers building from source
220
221 ## Installing DPorts tree
222
223 DragonFly 3.4 or later is the minimum version that can build DPorts from source.
224
225 It's probably that pkgsrc binaries are already installed because it comes bootstrapped with new systems.  It is necessary to rename `/usr/pkg` directory so that the existing pkgsrc binary tools and libraries don’t get accidentally used while building DPorts, causing breakage.  For the installation of the DPorts tree, type:
226
227     # cd /usr
228     # make dports-create-shallow
229
230 If the `/usr/pkg directory` has already been renamed, `git` won’t be in the search path any more.  One option is to download a tarball of DPorts and unpack it.  To do this, type:
231
232     # cd /usr
233     # make dports-download
234
235 For future updates, pull delta changes via `git` is fastest, so it is suggested to convert the static tree to a git repository by typing:
236
237     # cd /usr/dports/devel/git
238     # make install
239     # cd /usr
240     # rm -rf /usr/dports
241     # make dports-create-shallow
242
243 The git repository is hosted on the [github account of John Marino](https://github.com/jrmarino/DPorts/#readme).
244
245 ## Final thoughts
246
247 Building from source works similar to ports and pkgsrc: cd into the appropriate program's directory, and type 'make'. 'make install' to install the software, 'make clean' to clean up work files, and so on. Use 'make config-recursive' if you want to set all the port's options, and the options of its dependencies, immediately instead of during the build.
248
249 To take all the default build options and avoid getting the pop-up dialog box, set `NO_DIALOG=yes` on either the command line or the make.conf file.
250
251 If you just want to set the options for one package, and accept the default for all of its dependencies, do 'make config' in the package in you want non-default options, and then 'make NO_DIALOG=yes'.  Note that this is only necessary if you want to build from source with a non-default set of options, or if no pre-built binary package is available yet.
252
253 ## More reading
254 * How fix/add broken ports: [[docs/howtos/fixdports]]
255 * [Trick: How to get i386-only software via dports](http://leaf.dragonflybsd.org/mailarchive/users/2013-06/msg00023.html)