Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)

Posted on in Categories , , , last updated December 11, 2017

I have a Red Hat Enterprise Linux version 5 installed on one of the production server. However, I noticed that there is no GNU c/c++ compiler installed on the RHEL 5/RHEL 6 based system. I need to compile a few applications on this box. How do I install C or C++ compiler on Red Hat Enterprise Linux 5/6? Where can I get / download compiler package?

In order to compile and use c/c++ under RHEL you need the following packages:
=> autoconf : GNU’s Autoconf is a tool for configuring source code and Makefiles.
=> make/automake : A GNU tool for controlling the generation of executables and other non-source files of a program from the program’s source files.

=> GNU GCC C compiler (gcc) : The gcc package contains the GNU Compiler Collection version 4.1+

=> GNU GCC C++ compiler (gcc-c++): This package adds C++ support to the GNU Compiler Collection.

You have total 3 options to download and install GCC compiler under Redhat / CentOS / Fedora Linux:

  • Use GUI tool to install compiler set
  • Install compiler rpms from CDROM/DVD
  • Download and install compiler from RHN over the Internet

Option # 1: Use GUI tool to install c/c++ compiler set

You can use a GUI tool called system-config-packages to install gcc. Just type the following command and select gcc and above packages:
$ system-config-packages &

Option # 2: Install rpm from CDROM/DVD

Mount your RHEL/CentOS Linux CD/DVD and install the following packages using rpm command:
# rpm -ivh gcc*

Option # 3: Download and install compiler from RHN over the Internet

You can download and install packages using RHN and yum command:
# yum install gcc gcc-c++ autoconf automake

This entry is 4 of 13 in the Linux GNU/GCC Compilers Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Install GNU GCC Compiler and Development Environment
  2. Debian Linux Install GNU GCC Compiler and Development Environment
  3. CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
  4. Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)
  5. Mac OS X: Install GCC Compiler with Xcode
  6. Where is My Linux GNU C or GCC Compilers Are Installed?
  7. HowTo: Compile And Run a C/C++ Code In Linux
  8. RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
  9. HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD
  10. How To Install ncurses Library on a Linux
  11. Linux Find Out What Compilers Are Installed or Available On The System
  12. Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel
  13. Howto see output of C program in Linux or UNIX

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 83 comments/add one below):

83 comment

  1. This really is one of the clearest and most helpful answers to a tech question that I’ve ever seen. I’ve just taken on a RHEL v5 server and needed gcc installed – ten minutes after finding this site, I have gcc 4.1.2 installed. This must have saved me a few hours of searching and reading install instructions . . .

    I found your site through Google but have now bookmarked it and I’ll be back!

  2. in reading your blog i’m as confused and lost as ethernet is to phone transmission; i installed mandriva free and that is the os i’m using at present; i then foolishly bought their powerpack, thinking it would solve the problems that mandriva one was presenting to me; having downloaded it and installed it due to my ignorance in handling this os i made it unusable; i then repeatedly tried to reinstall it only to find that the operating system will not load giving me an error message: fatal error message which i cannot overcome, yet.
    can you help?

  3. After typing the following command “$ which gcc” to verify that gcc is installed, the Output was “/usr/bin/which: no gcc in (/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/omar/bin)
    ” , instead of being “/usr/bin/gcc”. what i have to do now?

  4. Hi,

    I have a program consists of header files, .cpp, .c, a Makefile and need to include the problem instances file (.tim).

    May i know how to compile and run them? From google, i have heard bout the command make. But i have no idea how. Please kindly help..

    Thanks..

    Regards,
    limeng

    1. hi i have installed fedora in my laptop but when i have execute c code in terminal
      by using command gcc myprog.c
      But it gives an error that gcc command is not found so tell me fast how to install gcc in fedora.Give me reply fast please;

  5. i have a problem that when i type ./a.out for output then some time it runs and some time it shows bash command so wat should i do in order to run program of doublly linked list as it is running in c compiler

  6. I’ve tried to install gcc 4 to linpus. I type the command on the terminal through directory objdir.
    However, I couldn’t finished. the terminal scroll and show, error in path: my documents/gcc4/objdir.
    Anyone can tell the steps?

  7. I would consider myself a beginner in the Linux world…I know enough to be dangerous. Very clear instructions. Followed Option 3 and had everything installed in about a minute.

  8. hello,
    thanx for the installation steps…but i still have problems installing the gcc. during the configuration it says
    checking the correct version of gmp/mpfr/mpc libraries no
    but i have already installed gmp mpfr and mpc as per the version mentioned for installation.
    thank you

  9. i have installed redhat 5 version in windows 7 using vmware.in it c copiler is working fine.but i cant compile c++ programs in it.what is the reason ?do i have to download anything further ?plz reply fast i am in great need now ,,i wiil be very thankful to u

    thanks in advance

  10. [[email protected] Desktop]$ cd ..
    [[email protected] ~]$ cd omnetpp-4.1
    [[email protected] omnetpp-4.1]$ ./configure
    checking build system type… x86_64-unknown-linux-gnu
    checking host system type… x86_64-unknown-linux-gnu
    configure: ———————————————–
    configure: reading configure.user for your custom settings
    configure: ———————————————–
    checking for icc… no
    checking for gcc… gcc
    checking for C compiler default output file name… a.out
    checking whether the C compiler works… yes
    checking whether we are cross compiling… no
    checking for suffix of executables…
    checking for suffix of object files… o
    checking whether we are using the GNU C compiler… yes
    checking whether gcc accepts -g… yes
    checking for gcc option to accept ISO C89… none needed
    checking for icpc… no
    checking for g++… no
    checking for c++… no
    checking for cxx… no
    checking for xlC… no
    checking whether we are using the GNU C++ compiler… no
    checking whether g++ accepts -g… no
    checking for g++… not found
    configure: error: No C++ compiler found — one is required to build OMNeT++/OMNEST, and also for model development.
    [[email protected] omnetpp-4.1]$

  11. i have the same problem..i have installed centos 6.0 along with windows 7…i can complile c programs but not c++ programs…pls help me for this problem as i have to install omnet++ on centos and it does not work without GNU c++ compliler…

  12. hello all
    i’ve used this command
    # yum install gcc gcc-c++ autoconf automake
    to install gcc compiler in my fedora16 os.
    but when i compile and run my first c++ program (helloworld.cpp) using command
    gcc input-file.cpp -o output-file (gcc helloworld.cpp -o helloworld)
    it gives error
    helloworld.cpp:3:18: fatal error: conio.h: No such file or directory
    compilation terminated.
    please help..!
    thank you…

  13. Hi
    i need one help for your side please tell me the where can i downloaded gcc compiler for Rhel5 64 bit and how to install the process i downloaded so many gcc compilers but its not working properly. i downloaded rpm packages its asking dependencies please help me out this problem guys…

  14. The pre-requisite for installing gcc is to have the ‘C’ compiler but on my RedHat 5.4 system, I don’t see the C compiler. Can someone please point how to get “C” compiler?

  15. I am getting below error , now what alternative i have to install gcc compiler

    [[email protected] ~]# yum install gcc gcc-c++ autoconf automake
    Gathering header information file(s) from server(s)
    Server: Red Hat Linux 16 - x86_64 - Base
    
    retrygrab() failed for:
      http://mirror.dulug.duke.edu/pub/yum-repository/redhat/16/x86_64/headers/header.info
      Executing failover method
    failover: out of servers to try
    Error getting file http://mirror.dulug.duke.edu/pub/yum-repository/redhat/16/x86_64/headers/header.info
    [Errno 4] IOError: 
    
  16. I an trying to install GCC on my linux CentOS 5.3 machine and i can not install gcc using yum because of no inetrnet connection,i downloaded all required rpm files and trying to install using rpm -Uvh package name of gcc,but it is asking so many dependent packages and even i downloaded all after that it is conflicking some packages with linux packages,please could you suggest any document or installation step including with solution if we face any package conflicts with GCC rpm packages

  17. Great post.
    I would add, that if you have any troubles with finding CD/DVD installation disc of RHEL, you can downloaded it from vault-centos. There you can find all the rmp needed for gcc installation (as well as their dependencies).

  18. [[email protected] ~]$ sudo dnf install gcc-c++

    We trust you have received the usual lecture from the local System
    Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

Leave a Comment