215

How do I install g++ for Fedora Linux? I have been searching the dnf command to install g++ but didn't find anything.

How do I install it?

I have already installed gcc

1
  • You probably need to install a package perhaps named g++-4.7 (or g++-4.6). Commented Oct 18, 2012 at 10:50

11 Answers 11

313

The package you're looking for is confusingly named gcc-c++.

3
  • I got this error during the install: bugzilla.redhat.com/show_bug.cgi?id=494006. Running yum clean metadata resolved the error and I was able to install gcc-c++.
    – yellavon
    Commented May 5, 2014 at 18:35
  • 3
    It's worth noting that this is discoverable by doing sudo yum install /usr/bin/g++ (or sudo yum install /usr/bin/g++).
    – mattdm
    Commented Apr 6, 2016 at 22:57
  • 2
    Alternately, without having to know exactly where the binary ends up, you can do yum whatprovides '*bin/g++' or even yum whatprovides '*/g++'.
    – asciiphil
    Commented May 6, 2016 at 14:15
149

instead of g++ you have to write gcc-c++

sudo dnf install gcc-c++
3
  • I have already installed gcc. I have been compiling c using the same
    – saplingPro
    Commented Oct 18, 2012 at 10:53
  • 5
    g++ is like an aditional for gcc, so if you want g++ the package you need is gcc-c++, try it... Commented Oct 18, 2012 at 10:56
  • 1
    with 22 its rather sudo dnf install gcc-c++ -y
    – DiCaprio
    Commented Jul 25, 2015 at 8:26
41

You should exec:

dnf install gcc-c++
18

Run the command bellow in a terminal emulator:

sudo dnf install gcc-c++

Enter password and that's it...

13

I had the same problem. At least I could solve it with this:

sudo yum install gcc gcc-c++

Hope it solves your problem too.

0
9

try sudo dnf update and then sudo dnf install gcc-c++

3
  • 3
    Update is not required. This is where fedora differs from debian
    – xiamx
    Commented Aug 23, 2015 at 0:49
  • 1
    update will update the current software, though. (like upgrade under Debian) It could be useful. Commented Feb 24, 2017 at 22:18
  • 1
    It's always a good idea to update the current software before adding new packages. It's not necessary, but you can get into some weird situations (particularly around multiarch) if you don't.
    – mattdm
    Commented Oct 31, 2017 at 12:07
6

Since Fedora 22 yum has been deprecated so the commands given in other answers will actually fire up 'Dandified yum' i.e. dnf. So the new command to install g++ in recent distributions is

su -c "dnf install gcc-c++"

As of Nov 2015 this installs the 5.1.1 version.
Also note that in Fedora 23 when I gave the command g++ -v, Fedora automatically asked me if I want to install gcc-c++ package. I think thats nice.(After the install it also ran the command g++ -v for me)
Only nit pick that I can do about it is that instead of a progress indicator you just get * Downloading packages... message which you may not like if you are on a slow internet connection.

4

In the newer distribution you can just type command as blow

su root
dnf update
dnf install gcc-c++
3
  • 1
    Unfortunately, the gcc-g++ package does not exist.
    – Motine
    Commented Mar 10, 2016 at 18:13
  • Again, note c++ not g++ in the package name.
    – mattdm
    Commented Oct 31, 2016 at 11:15
  • As of now (2020-04-20) both dnf install g++ and dnf install gcc-g++ resolve to gcc-c++ (and tell me it's already installed :)). [for the sake of future visitors] Commented Apr 19, 2020 at 23:38
4

this worked for me on Fedora 36:

sudo dnf groupinstall c-development

It will install the cc (gcc) and c++ (g++):

enter image description here

1

Just make a sample 'Hello World' Program and try to compile it using "g++ sam.cpp" in terminal, and it will ask you if you wish to download the g++ package. Press y to install.

1
  • I believe this only is the case in some spins.
    – Newbyte
    Commented Apr 26, 2020 at 16:56
1

Following are the steps to install and configure C++ compiler i.e. g++ compiler in Fedora OS -

  • Check for update - sudo dnf update
  • Upgrade the packages - sudo dnf upgrade
  • Install the g++ compiler - sudo dnf install gcc-c++
  • Verify the installed version of compiler - sudo dnf install gcc-c++

Not the answer you're looking for? Browse other questions tagged or ask your own question.