Linux create RPM and local repository

Example of RPM and YUM on CentOS 6.
1. Install the RPM build environment:
lin60 # yum install -y rpm-build rpmdevtools

2. Create the directory for the RPM environment
and the directory in which your program will be installed.
lin60 # mkdir -p /opt/software/rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}
lin60 # mkdir /opt/myprog

3. Create the .rpmmacros file in your logindir. This is a minimal file. There's a lot more you can configure in that.
lin60 # echo "%packager root" > ~/.rpmmacros
lin60 # echo "%_topdir /opt/software/rpm" >> ~/.rpmmacros
lin60 # echo "%_tmppath /opt/software/rpm/tmp" >> ~/.rpmmacros

4. Create your software in the SOURCES directory.
lin60 # mkdir /opt/software/rpm/SOURCES/myprog-1/
lin60 # cd /opt/software/rpm/SOURCES/myprog-1/
lin60 # echo "echo myprog" >
lin60 # chmod +x

5. Create a tarfile of your package.
lin60 # cd /opt/software/rpm/SOURCES/
lin60 # tar czf myprog-1.0.tar.gz myprog-1/

6. To define how your software will be created into
an RPM package, you need a SPEC file. It should look like this:
lin60 # cat /opt/software/rpm/SPECS/myprog.spec
Name: myprog
Version: 1
Release: 0
Summary: myprog rpm
Source0: myprog-1.0.tar.gz
License: GPL
Group: devel
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-buildroot
The myprog script will echo myprog.
%setup -q
install -m 0755 -d $RPM_BUILD_ROOT/opt/myprog
install -m 0755 $RPM_BUILD_ROOT/opt/myprog/
echo myprog installed
%dir /opt/myprog

Requires: myprogdep
Will create a dependency on myprogdep

7. Build your RPM package.
lin60 # cd /opt/software/rpm
lin60 # rpmbuild -ba SPECS/myprog.spec

8.Install your rpm from RPMS/noarch
lin60 # cd /opt/software/rpm/RPMS/noarch
lin60 # rpm -ivh myprog-1-0.noarch.rpm

To install the RPM using yum, create a local repository:

yum install createrepo

create a file called local.repo in /etc/yum.repos.d

cat /etc/yum.repos.d/local.repo

name=Local Repository

create the repo directory
mkdir /opt/software/localrepo/

copy the rpm to the repository
cp /opt/software/rpm/RPMS/noarch/myprog-1-0.noarch.rpm /opt/software/localrepo/

createrepo /opt/software/localrepo/

yum install myprog


This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.