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