Ask Your Question
5

How do I install a src rpm with dnf?

asked 2016-04-30 11:46:04 -0600

Planetar gravatar image

Whenever I try to install a src rpm with dnf, I get an error message that says "Error: Will not install a source rpm package".

For example:

# dnf info gcc.src
Last metadata expiration check: 1:52:25 ago on Sat Apr 30 11:43:51 2016.
Available Packages
Name        : gcc
Arch        : src
Epoch       : 0
Version     : 5.1.1
Release     : 4.fc23
Size        : 78 M
Repo        : fedora-source
Summary     : Various compilers (C, C++, Objective-C, Java, ...)
URL         : http://gcc.gnu.org
License     : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and
            : BSD
Description : The gcc package contains the GNU Compiler Collection version 5.
            : You'll need this package in order to compile C code.

# dnf install gcc.src
Last metadata expiration check: 1:53:05 ago on Sat Apr 30 11:43:51 2016.
Error: Will not install a source rpm package (gcc-5.1.1-4.fc23.src).

I'm on Fedora 23 and have dnf 1.1.8.

I'm wondering what I might be doing wrong. (Since Fedora 23 I haven't been able to use yum; calls to yum just turn into invocations of dnf.)

Surely it cannot be that dnf does not permit the user to have the sources?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
10

answered 2016-05-02 08:37:25 -0600

jmt gravatar image

Some of these things you might already know, but I'm trying to write an answer that would benefit all readers.

You should install source packages as a non-root user. In order to do this, you need to install the package rpmdevtools. To build a source tree from an rpm package you also need rpm-build.

Download the source package:

dnf download --source gcc

If you have not already done so, create a directory hierarchy for rpm development:

rpmdev-setuptree

This will create a directory tree under ~/rpmbuild although it is not strictly necessary - the required directories are created one by one by other commands.

Then you can install the source package:

rpm -ivh gcc-5.3.1-6.fc23.src.rpm

At this point you probably don't have the necessary dependencies installed and without them the following steps won't work. So at this point as a root user or sudo install the missing dependencies:

sudo dnf builddep gcc

Check out the spec file name in ~/rpmbuild/SPECS and then unpack sources and apply patches:

rpmbuild -bp ~/rpmbuild/SPECS/gcc.spec

Take a look at various options of the rpmbuild command with rpmbuild --help or man rpmbuild

Also check out the available documentation: rpm -qd rpm-build and rpm -qd rpmdevtools

Of course you can do all this a the root user, but it is not recommended.

edit flag offensive delete link more

Comments

And finally to install, do something like sudo dnf install -y ~/rpmbuild/RPMS/x86_64/*.rpm

user02202017 gravatar imageuser02202017 ( 2017-03-11 06:25:37 -0600 )edit

If you did rpmbuild -bp ~/rpmbuild/SPECS/gcc.spec that did a

build through %prep (unpack sources and apply patches) from <specfile>

but if you want to compile without re-running the %prep step(where re-running it implies removing the already unpacked sources that the -bp step above just did), you'd do rpmbuild -bc --noprep ~/rpmbuild/SPECS/gcc.spec which does

build through %build (%prep, then compile) from <specfile>

constantoverride gravatar imageconstantoverride ( 2018-08-16 21:35:33 -0600 )edit

But what you actually want is the rpm, that is

build binary package only from <specfile>

which means you'd do rpmbuild -bb --noprep --nobuild (assuming you already did the -bp and -bc above, for which the --noprep and --nobuild here are supposed to skip for you, else if you don't specify them, everything is cleaned and rebuild from %prep then %build stages, so having ran -bp and -bc above would've been useless, assuming you didn't use ccache which if used would've been primed)

constantoverride gravatar imageconstantoverride ( 2018-08-16 21:36:16 -0600 )edit

Note: sudo dnf install rpmdevtools already installs the rpm-build package also (on Fedora 28, at least)

constantoverride gravatar imageconstantoverride ( 2018-08-16 21:46:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

4 followers

Stats

Asked: 2016-04-30 11:46:04 -0600

Seen: 17,215 times

Last updated: May 02 '16