Attachment 'Gentle-Intro-Building-RPMs.md'
Download 1 # Building RPM's with CentOS 6
2
3 ## Introduction
4 Many newer packages aren't available to Redhat/CentOS systems through the yum package manager. One alternative is to install your needed packages from source. This can be time-consuming, especially if you plan on creating more than one development environment, and for version consistency between developers and production. This tutorial will use node.js as an example since as of this writing, the node.js package isn't available through any of the standard, or extra yum repositories.
5
6 This tutorial will use a minimal CentOS 6.3 installation as a standard base to start from. You'll need the CentOS-Base.repo enabled to install the _Development Tools_ package and the _rpmdevtools_ package. The _rpmdevtools_ isn't a necessity, but it can help speed up some manual directory creation.
7
8 ## Install the Development tools
9 You'll first need to prepare your system by installing a compiler, and the rpm-build packages. The simplest way to make sure you have everything you need is to use yum's groupinstall to install the _Development Tools_ packages:
10
11 `$ yum groupinstall "Development Tools"`
12
13 This will install the needed compilers, the rpmbuild package, and quite a few other development packages that might come in handy.
14
15 ## Install RPM Development Tools
16 This group of packages is optional, but using the _RPM Development Tools_ creates the directory structure, and a sample SPEC file for you. You can also manually create the directories and SPEC file too.
17
18 Install the package from the CentOS-Base Repository:
19
20 `$ yum install rpmdevtools`
21
22 ## Prepare Your Directories
23
24 You should never build RPMs as root. Most guides recommend creating a specific user account solely for building RPMs.
25
26 Using the `rpmdev-setuptree` command, you can create all of the needed directories. This command will create an _rpmbuild_ directory within your user home directory and all of the necessary subdirectories within it.
27
28 Begin by issuing the command:
29
30 `$ rpmdev-setuptree`
31
32 This creates the _rpmbuild_ directory with the following structure:
33
34 rpmbuild/
35 ├── BUILD
36 ├── RPMS
37 ├── SOURCES
38 ├── SPECS
39 └── SRPMS
40
41 ## The SPEC File
42 The spec file is the heart of your package building process, and is essentially a list of shell-commands that are issued when your package is installed. It follows a standard structure with steps that include any pre-configuration, pointers to the source files, and post-installation steps. I found it simplest to follow a SPEC file from someone else's personal RPM. The example below is the one I used, which is available on [github](https://github.com/vibol/node-rpm-spec).
43
44 The [Fedora Wiki](http://fedoraproject.org/wiki/How_to_create_an_RPM_package#Creating_a_SPEC_file) and [rpm.org](http://www.rpm.org/max-rpm-snapshot/s1-rpm-build-creating-spec-file.html) go into much greater detail about the _SPEC_ file, and the RPM building process in general.
45
46 ### Sample nodejs.spec File
47
48 %define ver 0.8.20
49 %define rel 1
50 %define jobs 2
51
52 Name: nodejs
53 Version: %{ver}
54 Release: %{rel}
55 Summary: Node.js programs
56 Group: Applications/Internet
57 License: Copyright Joyent, Inc. and other Node contributors.
58 URL: http://nodejs.org
59
60 Source0: http://nodejs.org/dist/node-v%{version}.tar.gz
61 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
62 BuildRequires: python >= 2.6, openssl-devel, gcc-c++
63
64 Provides: nodejs
65 Obsoletes: nodejs
66
67 %description
68 Node.js is a server-side JavaScript environment that uses an asynchronous
69 event-driven model. This allows Node.js to get excellent performance based on
70 the architectures of many Internet applications.
71
72 %prep
73 %setup -q -n node-v%{version}
74
75 %build
76 export JOBS=%{jobs}
77 python ./configure --prefix=/usr
78 make
79
80 %install
81 rm -rf %{buildroot}
82 make install DESTDIR=%{buildroot}
83
84 %clean
85 rm -rf %{buildroot}
86
87 %files
88 %defattr(-,root,root,-)
89 %doc AUTHORS ChangeLog LICENSE README.md
90
91 /usr/bin/node
92 /usr/bin/npm
93 /usr/bin/node-waf
94 /usr/include/node
95 /usr/share/man/man1/node.1.gz
96 /usr/lib/node
97 /usr/lib/node_modules
98 /usr/lib/dtrace/node.d
99
100 %changelog
101 * Fri Feb 15 2013 Josh Strater <jstrater@gmail.com> 0.8.20-1
102 - RPM using upstream v0.8.20
103
104 * Tue Jan 22 2013 Joseph Hajduk <joseph@solidys.com> 0.8.18-1
105 - RPM using upstream v0.8.18
106
107 * Wed Oct 31 2012 Andre von Deetzen <vondeetzen@mgail.com> 0.8.14-1
108 - RPM using upstream v0.8.14
109
110 * Thu Apr 12 2012 Vibol Hou <vibol@hou.cc> 0.6.15-1
111 - RPM using upstream v0.6.15
112
113 * Thu Apr 14 2011 Chris Abernethy <cabernet@chrisabernethy.com> 0.4.6-1
114 - Initial rpm using upstream v0.4.6
115
116 ## Get the Source Code
117 In order to create an RPM package, you need to build the software that you want to install. This is where the _Development Tools_ package comes in handy since it includes the compiler you'll need.
118 To continue on, download the source code for your particular package and version that you want to use. We're using node.js for this example, which is available from [nodejs.org](http://nodejs.org/dist/v0.8.21/node-v0.8.21.tar.gz). Download this to your home directory:
119
120 `$ wget http://nodejs.org/dist/v0.8.21/node-v0.8.21.tar.gz`
121
122 ## Add the Source to your Build Directory
123 The RPM build process needs to access the source code for your package. Copy the file containing your source code to the `~/rpmbuild/SOURCES` directory.
124
125 If you look closer at the example _SPEC_ file, you'll see where the _rpmbuild_ command is directed to your source file:
126
127 > `Source0: http://nodejs.org/dist/node-v%{version}.tar.gz`
128
129 It may seem counter-intuitive, but the build process ignores the first section that comprises the URL for the source and looks for the filename specified with the `~/rpmbuild/SOURCES` directory. This file needs to be physically present within your directory.
130
131 Copy the file you downloaded to your `~/rpmbuild/SOURCES` directory now:
132
133 `$ cp ~/node-v0.8.21.tar.gz ~/rpmbuild/SOURCES`
134
135 ## Edit the _SPEC_ file for the Updated Version
136 The example _SPEC_ file lists version 0.8.20. Node.js will probably be updated when you attempt to build an RPM from it.
137
138 We need to update our _SPEC_file now to reflect the updated version for our package. Don't worry, it only involves three lines.
139
140 At the top of the _SPEC_ file, the line
141
142 > `%define ver 0.8.20`
143
144 should be changed to:
145
146 > `%define ver 0.8.21`
147
148 Now go to the bottom of the _SPEC_ file and add your changes to the section
149 > `%changelog`
150
151 like this:
152
153 * Tue Feb 26 2013 Your Name <your.email@address.com> 0.8.21
154 - RPM using upstream v0.8.21
155
156 This should be the first entry listed under the changelog section now:
157
158 %changelog
159 * Tue Feb 26 2013 Your Name <your.email@address.com> 0.8.21
160 - RPM using upstream v0.8.21
161
162 * Fri Feb 15 2013 Josh Strater <jstrater@gmail.com> 0.8.20-1
163 - RPM using upstream v0.8.20
164
165 * Tue Jan 22 2013 Joseph Hajduk <joseph@solidys.com> 0.8.18-1
166 - RPM using upstream v0.8.18
167
168 * Wed Oct 31 2012 Andre von Deetzen <vondeetzen@mgail.com> 0.8.14-1
169 - RPM using upstream v0.8.14
170
171 * Thu Apr 12 2012 Vibol Hou <vibol@hou.cc> 0.6.15-1
172 - RPM using upstream v0.6.15
173
174 * Thu Apr 14 2011 Chris Abernethy <cabernet@chrisabernethy.com> 0.4.6-1
175 - Initial rpm using upstream v0.4.6
176
177 ## Build the RPM
178 The final step after this preparation is to actually build the RPM. Use the `rpmbuild` command:
179
180 `$ rpmbuild -ba rpmbuild/SPEC/nodejs.spec`
181
182 After the `rpmbuild` command completes, you'll find your RPM within the `RPMS` directory below your `rpmbuild` directory. Each build is specific to the architecture used to build them,
183 **THIS NEEDS WORK**
184 BuildArch: no arch etc. explain test
185
186 ## Test the RPM
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.