Creating RPM Packages with FPM on Ubuntu- A Step-by-Step Guide
How to Make RPM with FPM on Ubuntu
In the world of Linux distributions, RPM (RPM Package Manager) is a widely used package management system. It is primarily used in Red Hat-based distributions such as CentOS and Fedora. However, it is also possible to create RPM packages on Ubuntu using the FPM (Flexible Package Manager). In this article, we will guide you through the process of making RPM packages with FPM on Ubuntu.
Firstly, you need to install FPM on your Ubuntu system. Open your terminal and run the following command:
“`
sudo apt-get update
sudo apt-get install ruby ruby-dev rubygems rubygems-integration
gem install fpm
“`
Once FPM is installed, you can start creating RPM packages. Let’s assume you have a directory containing all the necessary files for your package. We will use this directory as an example throughout the article.
Creating a Basic RPM Package
To create a basic RPM package, you need to define a spec file. This file contains all the information about your package, such as its name, version, description, and dependencies. Create a file named `package.spec` in your directory and add the following content:
“`
%define version 1.0.0
%define release 1%{?dist}
Name: example-package
Version: %{version}
Release: %{release}
Summary: A simple example package
License: MIT
URL: www.example.com
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
%description
This is a simple example package that demonstrates how to create RPM packages with FPM on Ubuntu.
%files
%{buildroot}/usr/local/bin/example-package
“`
In this spec file, we define the package name, version, release, summary, license, and URL. We also specify the build root directory, which is used to store the package’s files during the build process. Finally, we list the files that should be included in the package.
Building the RPM Package
Now that we have the spec file, we can build the RPM package using the following command:
“`
fpm -s dir -t rpm -n example-package -v 1.0.0 -p /path/to/output/directory .
“`
In this command, we specify the following options:
– `-s dir`: The package type is a directory.
– `-t rpm`: The target package format is RPM.
– `-n example-package`: The package name.
– `-v 1.0.0`: The package version.
– `-p /path/to/output/directory`: The output directory where the RPM package will be saved.
– `.`: The source directory containing the package files.
After running the command, FPM will process the spec file and create an RPM package named `example-package-1.0.0-1.noarch.rpm` in the specified output directory.
Verifying the RPM Package
To verify that the RPM package was created successfully, you can use the following command:
“`
rpm -i /path/to/output/directory/example-package-1.0.0-1.noarch.rpm
“`
This command will install the RPM package, and you can check if it was installed correctly by searching for it using the `rpm -qa` command.
In conclusion, creating RPM packages with FPM on Ubuntu is a straightforward process. By following the steps outlined in this article, you can easily package your applications and distribute them to Red Hat-based distributions.