df194443292cb2d9c6cb04db8eff3743fdc3e9dd
[ikiwiki.git] / docs / howtos / HowToPkgsrc.mdwn
1 [[!toc levels=2 ]]
2
3 ## History and Overview 
4 [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.
5
6 ## Installing pkgsrc 
7
8 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.  
9
10 As root:
11
12     # cd /usr
13     # make pkgsrc-create
14
15 to fetch the intial pkgsrc repository from the net, or
16
17     # cd /usr
18     # make pkgsrc-update
19
20 to update.
21
22 Edit /usr/Makefile to select a different download location, if desired.
23
24 This downloads the absolute most recent version of pkgsrc.  In a production environment, you may want a more stable release.  Check the section below titled "Tracking the stable branch" for more details.
25
26 ## Installing packages from source
27
28 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.
29
30     # cd /usr/pkgsrc/misc/screen
31     # bmake install clean
32
33 To find out the options that can affect how a program is built:
34
35     # bmake show-options
36
37 To change options:
38
39     # bmake PKG_OPTIONS.<package_name>="-option1 option2" install clean
40
41 Listing an option enables it.  Listing an option with a "-" before it disables the option.
42
43 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:
44
45      . PKG_OPTIONS.<package_name>=-option1 option2
46     
47 ## Installing pre-built packages 
48
49 Binary packages can be installed using pkg_radd:
50
51     # pkg_radd screen
52
53 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.
54
55 You can manually set PKG_PATH and use pkg_add to get the same effect, using a different server.
56
57     # setenv PKG_PATH http://avalon.dragonflybsd.org/packages/i386/DragonFly-2.7/stable
58     # pkg_add screen
59
60 *Note that 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 *
61
62 This will install most packages, but will not upgrade packages that are already installed.
63
64 ***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.***
65
66 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'.
67
68 ### Tracking the stable branch 
69
70 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.
71
72 To see the available branches:
73
74     cd /usr/pkgsrc 
75     git branch -r
76
77 To switch to a recent branch:
78
79     cd /usr/pkgsrc 
80     git branch pkgsrc-2010Q3 origin/pkgsrc-2010Q3
81
82 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.
83
84 After switching to a new branch, it can be downloaded with:
85
86     cd /usr/pkgsrc 
87     git checkout vendor
88     git pull
89
90 ### List all installed packages 
91
92 To obtain a list of all the packages that are installed on your system:
93
94     # pkg_info
95
96 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:
97
98     # pkg_info | grep xorg
99
100 ### Searching available packages 
101
102 Packages can be found using one of two ways. You can issue the command
103
104     # cd /usr/pkgsrc/
105     # bmake search key='package you are looking for'
106
107 from the /usr/pkgsrc directory.
108
109 There is also the pkglocate tool that comes with pkgsrc:
110
111     # /usr/pkgsrc/pkglocate 'package name'
112
113 Normal UNIX file finding commands will work (whereis, locate, or find).
114
115 It's also possible to browse website that show all the available pkgsrc packages, such as [http://pkgsrc.se/](http://pkgsrc.se)
116
117 ## Upgrading packages 
118
119 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.
120
121 pkg_rolling-replace: Rebuilds packages from source in dependency order.
122
123 pkgin: Downloads and installs binary packages.  Check the [[mirrors]] page for sites carrying binary packages to use with pkgin. 
124
125 pkg_chk: will update package by removing them and rebuilding them.  Warning: programs are unavailable until a rebuild finishes.  If they don't rebuild, it won't work.
126
127 'bmake update': 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.
128
129 'pkg_add -u': point at a local or online binary archive location to download and update packages.
130
131 **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.
132
133     bmake replace USE_DESTDIR=yes
134
135 or
136
137     pkg_add -u /path/to/newer/pkg
138
139 ## Removing packages
140
141 If a program was installed as a package:
142
143     # pkg_delete packagename
144
145 If a package was installed from the source files, you can also change to the directory they were installed from and issue the command:
146
147     # bmake deinstall
148
149 ### Remove associated files needed for building a package 
150
151 To remove the work file from building a package, and the package's dependencies:
152
153     # bmake clean clean-depends
154
155 This can be combined with other steps:
156
157     # bmake install clean clean-depends
158
159 ## Additional /usr/pkg/etc/mk.conf notes
160
161 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:
162
163     RCD_SCRIPTS_DIR=/etc/rc.d
164     PKG_RCD_SCRIPTS=YES
165
166 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.
167
168 Many other options can be set in this file; see /usr/pkgsrc/mk/defaults/mk.conf for examples.
169
170 ## What is WIP? 
171
172 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.
173
174 ## Links
175
176 * [http://www.netbsd.org/Documentation/pkgsrc/](http://www.netbsd.org/Documentation/pkgsrc/)
177
178 * [http://www.pkgsrc.se](http://www.pkgsrc.se)
179
180 * [http://wiki-static.aydogan.net/How_to_upgrade_packages](http://wiki-static.aydogan.net/How_to_upgrade_packages)
181
182 * 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'.
183
184 * [http://pkgsrc-wip.sourceforge.net](http://pkgsrc-wip.sourceforge.net), **w**ork **i**n **p**rogress packages not yet in official pkgsrc release
185
186 * An [in-depth explanation of pkgsrc](http://www.unixgarden.com/index.php/administration-reseau/netbsd-s01e03-gestion-des-paquets), in French.
187
188 * The #pkgsrc IRC channel on Freenode
189
190 * The #dragonflybsd IRC channel on EFnet