No commit message specified.
[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 ensure  __pkgng__ on a DragonFly BSD 3.4 or higher system is  ready for use, run the following BEFORE you try to use `pkg` the first time:
14
15     # cd /usr
16     # make dports-create
17     # rm -rf /usr/pkg
18     # pkg upgrade
19     # rehash
20
21 Since you may need to manually edit the configuration file `/usr/local/etc/pkg.conf`  here is the
22 usual command to edit it using the vi editor:
23
24      # vi /usr/local/etc/pkg.conf
25
26
27
28 Before using consult the man page (`man pkg`) and then try things like these examples:
29
30
31     # pkg search editors
32     # pkg install vim
33
34
35 To bootstrap __pkgng__ with a download on a very old version of DragonFly that is still using `pkgsrc` run:
36
37     # make pkg-bootstrap
38     # rehash
39     # pkg-static install -y pkg
40     # rehash
41
42 Note that this step is unnecessary for any newly installed release from DragonFly 3.4 onwards.
43
44 ## Configuring pkgng
45
46 Information previously contained in here worked for older versions of pkg, but as pkgng has undergone some changes, so too do the configurations.
47
48 Previously /usr/local/etc/pkg.conf was used and reference to a PACKAGESITE was made. This might still work but it'll complain.
49
50 # pkg update
51 pkg: PACKAGESITE in pkg.conf is deprecated. Please create a repository configuration file
52 Updating repository catalogue
53 pkg: Warning: use of http:// URL scheme with SRV records is deprecated: switch to pkg+http://
54
55 Insead, listen to the errors. Throw an octothorpe in front of that packagesite line, save it, and move on.
56
57 Go to /usr/local/etc/pkg/repos/
58
59 You should see something like this with an ls
60
61 df-latest.conf.sample   df-releases.conf.sample
62
63 cp or mv one of them to be .conf
64
65 edit the one you choose and make the following changes. (I edited the latest version)
66
67 Avalon: {
68         url             : pkg+http://mirror-master.dragonflybsd.org/dports/${ABI}/L\
69 ATEST,
70         mirror_type     : SRV,
71         signature_type  : NONE,
72         pubkey          : NONE,
73         fingerprints    : /usr/share/fingerprints,
74         enabled         : yes
75 }
76
77 Depending on when and how you installed and/or upgraded, you may have to chmod 644 the file first to be able to edit it.
78
79 ## Basic pkgng Operations
80
81 Usage information for __pkgng__ is available in the pkg(8) manual page, or by running `pkg` without additional arguments.
82
83 Each __pkgng__ command argument is documented in a command-specific manual page. To read the manual page for `pkg install`, for example, run either:
84
85     # pkg help install
86     # man pkg-install
87
88 ## Obtaining Information About Installed Packages with pkgng
89
90 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:
91
92     # pkg info packagename
93
94 For example, to see which version of __pkgng__ is installed on the system, run:
95
96     # pkg info pkg
97     pkg-1.0.12                   New generation package manager
98
99 ## Installing and Removing Packages with pkgng
100
101 In general, most DragonFly users will install binary packages by typing:
102
103     # pkg install <packagename>
104
105 For example, to install curl:
106
107     # pkg install curl
108
109     Updating repository catalogue
110     Repository catalogue is up-to-date, no need to fetch fresh copy
111     The following packages will be installed:
112     
113         Installing ca_root_nss: 3.13.5
114         Installing curl: 7.24.0
115     
116     The installation will require 4 MB more space
117     
118     1 MB to be downloaded
119     
120     Proceed with installing packages [y/N]: y
121     ca_root_nss-3.13.5.txz           100%    255KB   255.1KB/s  255.1KB/s   00:00
122     curl-7.24.0.txz                  100%   1108KB     1.1MB/s    1.1MB/s   00:00
123     Checking integrity... done
124     Installing ca_root_nss-3.13.5... done
125     Installing curl-7.24.0... done
126
127 The new package and any additional packages that were installed as dependencies can be seen in the installed packages list:
128
129     # pkg info
130     ca_root_nss-3.13.5    The root certificate bundle from the Mozilla Project
131     curl-7.24.0           Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
132     pkg-1.0.12            New generation package manager
133
134 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:
135
136     # pkg delete curl
137     The following packages will be deleted:
138     
139         curl-7.24.0_1
140     
141     The deletion will free 3 MB
142     
143     Proceed with deleting packages [y/N]: y
144     Deleting curl-7.24.0_1... done
145
146 ## Upgrading Installed Packages with pkgng
147
148 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.
149
150 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:
151
152     # pkg upgrade
153     Updating repository catalogue
154     repo.txz            100%    297KB   296.5KB/s   296.5KB/s   00:00
155     The following packages will be upgraded:
156     
157     Upgrading curl: 7.24.0 -> 7.24.0_1
158     
159     1 MB to be downloaded
160     
161     Proceed with upgrading packages [y/N]: y
162     curl-7.24.0_1.txz   100%    1108KB  1.1MB/s       1.1MB/s   00:00
163     Checking integrity... done
164     Upgrading curl from 7.24.0 to 7.24.0_1... done
165
166 ## Auditing Installed Packages with pkgng
167
168 Occasionally, software vulnerabilities may be discovered in software within DPorts. __pkgng__ includes built-in auditing. To audit the software installed on the system, type:
169
170     # pkg audit -F
171
172 # Advanced pkgng Operations
173
174 ## Automatically Removing Leaf Dependencies with pkgng
175
176 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:
177
178     # pkg autoremove
179     Packages to be autoremoved:
180         ca_root_nss-3.13.5
181     
182     The autoremoval will free 723 kB
183     
184     Proceed with autoremoval of packages [y/N]: y
185     Deinstalling ca_root_nss-3.13.5... done
186
187 ## Backing Up the pkgng Package Database
188
189 __pkgng__ includes its own package database backup mechanism. To manually back up the package database contents, type:
190
191     # pkg backup -d <pkgng.db>
192
193 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).
194
195 To restore the contents of a previous package database backup, run:
196
197     # pkg backup -r </path/to/pkgng.db>
198
199 ## Removing Stale pkgng Packages
200
201 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.
202
203 To remove the outdated binary packages, type:
204
205     # pkg clean
206
207 ##Modifying pkgng Package Metadata
208
209 __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:
210
211     # pkg set -o <category/oldport>:<category/newport>
212
213 For example, to change the package origin for the above example, type:
214
215     # pkg set -o lang/php5:lang/php53
216
217 As another example, to update lang/ruby18 to lang/ruby19, type:
218
219     # pkg set -o lang/ruby18:lang/ruby19
220
221 As a final example, to change the origin of the libglut shared libraries from graphics/libglut to graphics/freeglut, type:
222
223     # pkg set -o graphics/libglut:graphics/freeglut
224
225 _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:
226
227     # pkg install -Rf graphics/freeglut
228
229 # Building DPorts from source
230
231 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:
232
233 * The port is new and there's no pre-binary available yet
234 * The pre-built binaries use the default options and the user needs a package built with a different set of options
235 * Testing FreeBSD port in order to patch them and submit to DPorts
236 * The user just prefers building from source
237
238 ## Installing DPorts tree
239
240 DragonFly 3.4 or later is the minimum version that can build DPorts from source.
241
242 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:
243
244     # cd /usr
245     # make dports-create-shallow
246
247 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:
248
249     # cd /usr
250     # make dports-download
251
252 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:
253
254     # cd /usr/dports/devel/git
255     # make install
256     # cd /usr
257     # rm -rf /usr/dports
258     # make dports-create-shallow
259
260 The git repository is hosted on the [github account of John Marino](https://github.com/jrmarino/DPorts/#readme).
261
262 ## Final thoughts
263
264 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.
265
266 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.
267
268 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.
269
270 ## More reading
271 * How fix/add broken ports: [[docs/howtos/fixdports]]
272 * [Trick: How to get i386-only software via dports](http://leaf.dragonflybsd.org/mailarchive/users/2013-06/msg00023.html)