3

On Fedora 35:

# dnf install g++   
Last metadata expiration check: 0:07:14 ago on Fri May  6 09:44:09 2022.
Package gcc-c++-11.3.1-2.fc35.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
# dnf info g++   
Last metadata expiration check: 0:08:26 ago on Fri May  6 09:44:09 2022.
Error: No matching Packages to list

I know gcc-c++ is a package, which I should be installing if I want to compile C++.

Why does installing (and even removing!) g++ work if it is not a package?

Bonus question: how can I check if gcc-c++ is installed by only referencing g++ and not its real name?

1 Answer 1

7

When you run dnf install <something>, it will first look for a package name <something>, but then it will look for a package that provides <something>. A "provides" value is effectively a virtual package name (set using the Provides: keyword in the RPM spec file).

We can see what packages provide g++ by running:

dnf repoquery --whatprovides g++

Which (on Fedora 35) produces:

gcc-c++-0:11.2.1-1.fc35.i686
gcc-c++-0:11.2.1-1.fc35.x86_64
gcc-c++-0:11.3.1-2.fc35.x86_64

The dnf repoquery command queries your repository configuration. You can also ask the same question about locally installed packages using rpm -q --whatprovides, so to do this:

Bonus question: how can I check if gcc-c++ is installed by only referencing g++ and not its real name?

Just run:

rpm -q --whatprovides g++

The return code will tell you whether any installed package provides g++.


This feature is often used to specify package dependencies that are linked to a particular capability, rather than a specific package. For example, if you have something that requires a webserver, rather than making it depend on a particular package (e.g., httpd or nginx), you can write in your spec file:

Requires: webserver

And then if any one of these packages is installed the dependency will be satisfied:

$ dnf repoquery --whatprovides webserver
caddy-0:2.3.0-2.fc35.x86_64
httpd-0:2.4.51-2.fc35.x86_64
httpd-0:2.4.53-1.fc35.x86_64
lighttpd-0:1.4.59-3.fc35.x86_64
lighttpd-0:1.4.64-1.fc35.x86_64
nginx-1:1.20.1-6.fc35.x86_64
nginx-1:1.20.2-1.fc35.x86_64

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .