Add TOC to DPorts page
[ikiwiki.git] / docs / howtos / HowToDPorts / index.mdwn
1 [[!toc  levels=3]]
2
3 # DPorts and pkgng
4
5 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.
6
7 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.  FreeBSD has since removed their legacy tools so __pkgng__ is exclusively used by FreeBSD as well.
8
9 __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.  On the other hand, many people use __pkgng__ by itself and never install the optional portupgrade or portmaster tools.
10
11 ## Getting started with pkgng
12
13 DragonFly daily snapshots and Releases (starting with 3.4) come with __pkgng__ already installed.  Upgrades from earlier releases, however, will not 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 or even having dports installed:
14
15     # make pkg-bootstrap
16     # rehash
17     # pkg-static install -y pkg
18     # rehash
19
20 If pkgsrc has ever been installed on the system, make sure all binaries produced by it have been removed:
21
22     # rm -rf /usr/pkg
23
24 Currently it's necessary to manually install the configuration file, but this requirement should disappear in the future.  After installing the configuration file, you may want to open it up and edit it to select a different mirror.
25
26 ## Configuring pkgng
27
28 Older versions of pkgng saved their configuration at /usr/local/etc/pkg.conf; this file made reference to a PACKAGESITE.  pkgng will still work based on this file, but will output errors:
29
30     # pkg update
31     pkg: PACKAGESITE in pkg.conf is deprecated. Please create a repository configuration file
32     Updating repository catalogue
33     pkg: Warning: use of http:// URL scheme with SRV records is deprecated: switch to pkg+http://
34
35 If you do __not__ see these errors, then skip to "Now, navigate to `/usr/local/etc/pkg/repos/`", otherwise:
36
37 Listen to the errors: hash out the packagesite line, save the file, and move on.  This can be done with vi:
38
39     # vi /usr/local/etc/pkg.conf
40
41 There will be two lines in the file like this:
42
43     # Default DPorts package server (California)
44     PACKAGESITE: http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST
45
46 Hash out the offending line:
47
48     # Default DPorts package server (California)
49     # PACKAGESITE: http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST
50
51 Note that, as of time of writing, there are two working package repositories:
52
53     # Default DPorts package server (California)
54     # PACKAGESITE: http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST
55     
56     # European mirrors
57     [...]
58     #PACKAGESITE: http://dfly.schlundtech.de/dports/${ABI}/LATEST
59
60 Test their performance---we will be using the fastest one.  This may, or may not, be the one closest to you (the California site for the New World, the German site for the Old World).
61
62     # ping schlundtech.de
63     PING schlundtech.de (85.236.36.90): 56 data bytes
64     64 bytes from 85.236.36.90: icmp_seq=0 ttl=49 time=101.433 ms
65     64 bytes from 85.236.36.90: icmp_seq=1 ttl=49 time=59.177 ms
66     64 bytes from 85.236.36.90: icmp_seq=2 ttl=49 time=79.550 ms
67     64 bytes from 85.236.36.90: icmp_seq=3 ttl=49 time=88.268 ms
68     64 bytes from 85.236.36.90: icmp_seq=4 ttl=49 time=120.060 ms
69     [...]
70     --- schlundtech.de ping statistics ---
71     20 packets transmitted, 19 packets received, 5.0% packet loss
72     round-trip min/avg/max/stddev = 49.555/96.064/186.662/33.559 ms
73     # ping mirror-master.dragonflybsd.org
74     PING avalon.dragonflybsd.org (199.233.90.72): 56 data bytes
75     64 bytes from 199.233.90.72: icmp_seq=0 ttl=47 time=208.013 ms
76     64 bytes from 199.233.90.72: icmp_seq=1 ttl=47 time=256.441 ms
77     64 bytes from 199.233.90.72: icmp_seq=2 ttl=47 time=281.436 ms
78     64 bytes from 199.233.90.72: icmp_seq=3 ttl=47 time=281.103 ms
79     64 bytes from 199.233.90.72: icmp_seq=4 ttl=47 time=285.440 ms
80     [...]
81     --- avalon.dragonflybsd.org ping statistics ---
82     19 packets transmitted, 19 packets received, 0.0% packet loss
83     round-trip min/avg/max/stddev = 208.013/264.017/334.180/31.549 ms
84
85 Now, navigate to `/usr/local/etc/pkg/repos/` and rename one of the configuration file samples you find there. `df-latest.conf` will make pkg use the newest available binaries while `df-release.conf` points to binaries built at the time of the release. The latter is frozen so you will not get any updates. Edit the one you renamed:
86
87     # cd /usr/local/etc/pkg/repos/
88     # ls
89     df-latest.conf.sample       df-releases.conf.sample
90     # cp -v df-latest.conf.sample df-latest.conf
91     df-latest.conf.sample -> df-latest.conf
92     # chmod -v 644 df-latest.conf
93     df-latest.conf
94     # vi df-latest.conf
95
96 Enable whichever server was faster (Avalon is American, SchlundTech is German), and pkg+ to the url and SRV to mirror_type:
97
98     Avalon: {
99         url             : pkg+http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST,
100         mirror_type     : SRV
101         [...]
102         enabled         : no
103     }
104     SchlundTech: {
105         url             : pkg+http://dfly.schlundtech.de/dports/${ABI}/LATEST,
106         mirror_type     : SRV
107         [...]
108         enabled         : yes
109     }
110
111 Before using, consult the man page (`man pkg`) and then try these examples:
112
113     # pkg search editors
114     # pkg install vim
115
116 ## Basic pkgng Operations
117
118 Usage information for __pkgng__ is available in the pkg(8) manual page, or by running `pkg` without additional arguments.
119
120 Each __pkgng__ command argument is documented in a command-specific manual page. To read the manual page for `pkg install`, for example, run either:
121
122     # pkg help install
123     # man pkg-install
124
125 ## Obtaining Information About Installed Packages with pkgng
126
127 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:
128
129     # pkg info packagename
130
131 For example, to see which version of __pkgng__ is installed on the system, run:
132
133     # pkg info pkg
134     pkg-1.0.12                   New generation package manager
135
136 ## Installing and Removing Packages with pkgng
137
138 In general, most DragonFly users will install binary packages by typing:
139
140     # pkg install <packagename>
141
142 For example, to install curl:
143
144     # pkg install curl
145
146     Updating repository catalogue
147     Repository catalogue is up-to-date, no need to fetch fresh copy
148     The following packages will be installed:
149     
150         Installing ca_root_nss: 3.13.5
151         Installing curl: 7.24.0
152     
153     The installation will require 4 MB more space
154     
155     1 MB to be downloaded
156     
157     Proceed with installing packages [y/N]: y
158     ca_root_nss-3.13.5.txz           100%    255KB   255.1KB/s  255.1KB/s   00:00
159     curl-7.24.0.txz                  100%   1108KB     1.1MB/s    1.1MB/s   00:00
160     Checking integrity... done
161     Installing ca_root_nss-3.13.5... done
162     Installing curl-7.24.0... done
163
164 The new package and any additional packages that were installed as dependencies can be seen in the installed packages list:
165
166     # pkg info
167     ca_root_nss-3.13.5    The root certificate bundle from the Mozilla Project
168     curl-7.24.0           Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
169     pkg-1.0.12            New generation package manager
170
171 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:
172
173     # pkg delete curl
174     The following packages will be deleted:
175     
176         curl-7.24.0_1
177     
178     The deletion will free 3 MB
179     
180     Proceed with deleting packages [y/N]: y
181     Deleting curl-7.24.0_1... done
182
183 ## Upgrading Installed Packages with pkgng
184
185 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.
186
187 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:
188
189     # pkg upgrade
190     Updating repository catalogue
191     repo.txz            100%    297KB   296.5KB/s   296.5KB/s   00:00
192     The following packages will be upgraded:
193     
194     Upgrading curl: 7.24.0 -> 7.24.0_1
195     
196     1 MB to be downloaded
197     
198     Proceed with upgrading packages [y/N]: y
199     curl-7.24.0_1.txz   100%    1108KB  1.1MB/s       1.1MB/s   00:00
200     Checking integrity... done
201     Upgrading curl from 7.24.0 to 7.24.0_1... done
202
203 ## Auditing Installed Packages with pkgng
204
205 Occasionally, software vulnerabilities may be discovered in software within DPorts. __pkgng__ includes built-in auditing. To audit the software installed on the system, type:
206
207     # pkg audit -F
208
209 # Advanced pkgng Operations
210
211 ## Automatically Removing Leaf Dependencies with pkgng
212
213 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:
214
215     # pkg autoremove
216     Packages to be autoremoved:
217         ca_root_nss-3.13.5
218     
219     The autoremoval will free 723 kB
220     
221     Proceed with autoremoval of packages [y/N]: y
222     Deinstalling ca_root_nss-3.13.5... done
223
224 ## Backing Up the pkgng Package Database
225
226 __pkgng__ includes its own package database backup mechanism. To manually back up the package database contents, type:
227
228     # pkg backup -d <pkgng.db>
229
230 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).
231
232 To restore the contents of a previous package database backup, run:
233
234     # pkg backup -r </path/to/pkgng.db>
235
236 ## Removing Stale pkgng Packages
237
238 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.
239
240 To remove the outdated binary packages, type:
241
242     # pkg clean
243
244 ##Modifying pkgng Package Metadata
245
246 __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:
247
248     # pkg set -o <category/oldport>:<category/newport>
249
250 For example, to change the package origin for the above example, type:
251
252     # pkg set -o lang/php5:lang/php53
253
254 As another example, to update lang/ruby18 to lang/ruby19, type:
255
256     # pkg set -o lang/ruby18:lang/ruby19
257
258 As a final example, to change the origin of the libglut shared libraries from graphics/libglut to graphics/freeglut, type:
259
260     # pkg set -o graphics/libglut:graphics/freeglut
261
262 _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:
263
264     # pkg install -Rf graphics/freeglut
265
266 # Building DPorts from source
267
268 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:
269
270 * The port is new and there's no pre-binary available yet
271 * The pre-built binaries use the default options and the user needs a package built with a different set of options
272 * Testing FreeBSD port in order to patch them and submit to DPorts
273 * The user just prefers building from source
274
275 ## Installing DPorts tree
276
277 DragonFly 3.4 or later is the minimum version that can build DPorts from source.
278
279 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:
280
281     # cd /usr
282     # make dports-create-shallow
283
284 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:
285
286     # cd /usr
287     # make dports-download
288
289 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:
290
291     # cd /usr/dports/devel/git
292     # make install
293     # cd /usr
294     # rm -rf /usr/dports
295     # make dports-create-shallow
296
297 The git repository is hosted on the [github account of John Marino](https://github.com/jrmarino/DPorts/#readme).
298
299 ## Final thoughts
300
301 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.
302
303 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.
304
305 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.
306
307 ## More reading
308 * How fix/add broken ports: [[docs/howtos/fixdports]]
309 * [Trick: How to get i386-only software via dports](http://leaf.dragonflybsd.org/mailarchive/users/2013-06/msg00023.html)