- Where is My Linux GNU C or GCC Compilers Are Installed?
- Syntax
- Displying gcc version:
- Installing GNU compiler collection
- If you are using Red Hat Enterprise Linux version 4.0 or older , type the command:
- If you are using CentOS/Fedora Linux or RHEL version 5.0 or above , type the command:
- If you are using Debian /Ubuntu Linux , type the command:
- Writing a sample test code
- Conclusion
- Gcc path in linux
Where is My Linux GNU C or GCC Compilers Are Installed?
W here is my GNU C compiler? Where does the GNU C (gcc) compiler reside in the RHEL / Fedora / Debian / Ubuntu / CentOS Linux installation? How do I install GNU c/c++ compiler in Linux operating systems?
The GNU Compiler Collection (GCC) is a compiler system. It was created by the GNU Project supporting various programming languages such as C (gcc), C++ (g++), Objective-C, Objective-C++, Fortran (gfortran), Java (gcj), Ada (GNAT), and Go (gccgo).
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | GNU gcc |
Est. reading time | 5m |
You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.
Syntax
Open a terminal and then type the following which command to see Linux C Compiler location:
$ which g++
$ which cc
$ which gcc
Sample outputs:
Another option is to use the type command as follows:
$ type -a gcc
$ type -a cc
$ type -a g++
OR use the command command as follows:
$ command -V gcc
$ command -V cc
$ command -V g++
Sample outputs:
Fig.01: Using various shell command to find out GNU compiler location
Displying gcc version:
Open terminal app and then type the following command
$ gcc -v
Here is what we see for GNU gcc c and c++ compiler:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Installing GNU compiler collection
You need to use the up2date command or yum command or apt-get command/apt command to install GNI C/C++ (gcc) and required libs as per your Linux distro.
Note: You must login as root using su — or sudo -s command and then use command as per your distro.
If you are using Red Hat Enterprise Linux version 4.0 or older , type the command:
If you are using CentOS/Fedora Linux or RHEL version 5.0 or above , type the command:
# yum group install «Development Tools»
If you are using Debian /Ubuntu Linux , type the command:
$ sudo apt-get install build-essential
OR
# apt-get install build-essential
Writing a sample test code
You can create a sample c code as follows:
$ vi foo.c
Append the following code:
Compile it as follows:
$ cc foo.c -o foo
$ ls -l foo
$ ./foo
Sample outputs:
Conclusion
You learned how to locate GNU gcc c and C++ compilers on Linux.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Hi this help is awesome it helps me a lot , i was looking for this commands in pages of my country(peru) but i didn’t find anything . thanks a lot .
You just saved my life! Thank you so much for the info…
Excellent work… Your help is really appreciate………….
it helped me a lot
Thanks….save me tons of time,, 🙂
thank u very much for the help
This tutorial helped me much. Thanks
1000 Thank Yous.
thx, i just installed it, much appreciated.
The smallest question “what is the gcc version” and u had it…Thanx a ton!
when I install faad2-2.7 in Optiplex 780 in fedora 13 window the compiler display
shime@localhost softwares]$
[shime@localhost softwares]$ cd faad2-2.7
[shime@localhost faad2-2.7]$ su
[root@localhost faad2-2.7]# ./configure
hecking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for gawk… gawk
checking whether make sets $(MAKE)… yes
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu
checking for style of include used by make… GNU
checking for gcc… no
checking for cc… no
checking for cl.exe… no
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details.
please help me how to solve this problem.
hi, when i type the command ‘ yum install gcc’ , i got a reply as ‘you need to be a root to perform this command…”
what does it mean??
It means you need to be superuser by using the command:
su
Then it will prompt for a password, then you will be able to install using the same command.
As an alternative log in as the root user.
when i giv the command “yum install gcc”, it says i need to be a root to perform this command… wht shld i do??
It means you need to google “you need to be a root to perform this command…”.
I have centos installed,
ls -l glibc-*
-rw-r–r– 1 root root 4596084 Jul 25 15:31 glibc-2.5-34.i386.rpm
-rw-r–r– 1 root root 5459594 Jul 25 15:31 glibc-2.5-34.i686.rpm
-rw-r–r– 1 root root 17249412 Jul 25 15:31 glibc-common-2.5-34.i386.rpm
error when install rpm packet.
rpm -ivh glibc-2.5-34.i386.rpm
error: glibc-2.5-34.i386.rpm: rpmReadSignature failed: region trailer: BAD, tag 15872 type 2047 offset 28672 count 4238
error: glibc-2.5-34.i386.rpm cannot be installed
error when install tar.gz
configure: error: no acceptable C compiler found in $PATH
]# gcc
-bash: gcc: command not found
(gcc not install).
How to install gcc ?
thx a lot
I had the need to be in root to perform this command error so I thought Id share the solution I found (im using centOS). I used the command – sudo yum install gcc-c++
BUT that is for c++ compiling so for C use sudo yum install gcc
It seems that you need to put sudo in front of the command to use root 0.o maybe.
Sudo will raise the priv level of the currently logged in user to execute the task listed after it (you can also find out more with: man sudo), it is like right clicking in Windows and selecting to run as administrator.
I have several error to comiple SPEC2006. can you help
specmake: icc: Command not found
Error with make ‘specmake build’
specmake: *** [spec.o] Error 127
Command returned exit code 2
Error with make!
how i get my c++ compiler in linux please give me steps n how i will compile my program
hey what should we give for password? it’s not taking any characters
just enter your password(log in one)
it will not show any thing on display but type your password & press enter .
installation will start
i want to clean gcc4.3 in ubuntu and install gcc2.96 .
i dont know how do .
please help me .
thanks
Hi,
I have few problems with my gcc,I feel its not installed at all,when I type the following commands I get the following response
# gcc -v
-bash: gcc: command not found
# sudo apt-get install gcc
sudo: apt-get: command not found
Please let me know how can I install gcc on my RHEL6
i got error msg -can not access archive while insataling gcc
what i have to do
Hi,
I found below error. Please help.
[root@localhost objdir]# yum install gcc
Loading “rhnplugin” plugin
Loading “installonlyn” plugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Setting up repositories
No Repositories Available to Set Up
Reading repository metadata in from local files
Parsing package install arguments
Setting up repositories
No Repositories Available to Set Up
Reading repository metadata in from local files
No Match for argument: gcc
Nothing to do
yum install gcc is not working in rhel 6 server.
Hi,
I am using Kubuntu
When I am giving command “# apt-get install gcc”
It will give error like this,
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package gcc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘gcc’ has no installation candidate
———————————–
Can you help me ?
Hi when I type in yum it says command not found. Help.
I got exactly what i was looking for in this tutorial, Thanks!
Hello,
Thank you for the useful information. I have an issue when I use the “type” command, it gives the following output:
gcc is /usr/bin/gcc
gcc is /bin/gcc
The same case is repeated when I run type cc and g++. Can you please help me to resolve this because Im having compiling issues.
Источник
Gcc path in linux
This section describes several environment variables that affect how GCC operates. Some of them work by specifying directories or prefixes to use when searching for various kinds of files. Some are used to specify other aspects of the compilation environment.
Note that you can also specify places to search using options such as -B , -I and -L (see Directory Options). These take precedence over places specified using environment variables, which in turn take precedence over those specified by the configuration of GCC. See Controlling the Compilation Driver gcc in GNU Compiler Collection (GCC) Internals .
LANG LC_CTYPE LC_MESSAGES LC_ALL
These environment variables control the way that GCC uses localization information which allows GCC to work with different national conventions. GCC inspects the locale categories LC_CTYPE and LC_MESSAGES if it has been configured to do so. These locale categories can be set to any value supported by your installation. A typical value is ‘ en_GB.UTF-8 ’ for English in the United Kingdom encoded in UTF-8.
The LC_CTYPE environment variable specifies character classification. GCC uses it to determine the character boundaries in a string; this is needed for some multibyte encodings that contain quote and escape characters that are otherwise interpreted as a string end or escape.
The LC_MESSAGES environment variable specifies the language to use in diagnostic messages.
If the LC_ALL environment variable is set, it overrides the value of LC_CTYPE and LC_MESSAGES ; otherwise, LC_CTYPE and LC_MESSAGES default to the value of the LANG environment variable. If none of these variables are set, GCC defaults to traditional C English behavior.
If TMPDIR is set, it specifies the directory to use for temporary files. GCC uses temporary files to hold the output of one stage of compilation which is to be used as input to the next stage: for example, the output of the preprocessor, which is the input to the compiler proper.
Setting GCC_COMPARE_DEBUG is nearly equivalent to passing -fcompare-debug to the compiler driver. See the documentation of this option for more details.
If GCC_EXEC_PREFIX is set, it specifies a prefix to use in the names of the subprograms executed by the compiler. No slash is added when this prefix is combined with the name of a subprogram, but you can specify a prefix that ends with a slash if you wish.
If GCC_EXEC_PREFIX is not set, GCC attempts to figure out an appropriate prefix to use based on the pathname it is invoked with.
If GCC cannot find the subprogram using the specified prefix, it tries looking in the usual places for the subprogram.
The default value of GCC_EXEC_PREFIX is prefix /lib/gcc/ where prefix is the prefix to the installed compiler. In many cases prefix is the value of prefix when you ran the configure script.
Other prefixes specified with -B take precedence over this prefix.
This prefix is also used for finding files such as crt0.o that are used for linking.
In addition, the prefix is used in an unusual way in finding the directories to search for header files. For each of the standard directories whose name normally begins with ‘ /usr/local/lib/gcc ’ (more precisely, with the value of GCC_INCLUDE_DIR ), GCC tries replacing that beginning with the specified prefix to produce an alternate directory name. Thus, with -Bfoo/ , GCC searches foo/bar just before it searches the standard directory /usr/local/lib/bar . If a standard directory begins with the configured prefix then the value of prefix is replaced by GCC_EXEC_PREFIX when looking for header files.
The value of COMPILER_PATH is a colon-separated list of directories, much like PATH . GCC tries the directories thus specified when searching for subprograms, if it cannot find the subprograms using GCC_EXEC_PREFIX .
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH . When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it cannot find them using GCC_EXEC_PREFIX . Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first).
This variable is used to pass locale information to the compiler. One way in which this information is used is to determine the character set to be used when character literals, string literals and comments are parsed in C and C++. When the compiler is configured to allow multibyte characters, the following values for LANG are recognized:
Recognize JIS characters.
Recognize SJIS characters.
Recognize EUCJP characters.
If LANG is not defined, or if it has some other value, then the compiler uses mblen and mbtowc as defined by the default locale to recognize and translate multibyte characters.
If GCC_EXTRA_DIAGNOSTIC_OUTPUT is set to one of the following values, then additional text will be emitted to stderr when fix-it hints are emitted. -fdiagnostics-parseable-fixits and -fno-diagnostics-parseable-fixits take precedence over this environment variable.
Emit parseable fix-it hints, equivalent to -fdiagnostics-parseable-fixits . In particular, columns are expressed as a count of bytes, starting at byte 1 for the initial column.
As fixits-v1 , but columns are expressed as display columns, as per -fdiagnostics-column-unit=display .
Some additional environment variables affect the behavior of the preprocessor.
CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH
Each variable’s value is a list of directories separated by a special character, much like PATH , in which to look for header files. The special character, PATH_SEPARATOR , is target-dependent and determined at GCC build time. For Microsoft Windows-based targets it is a semicolon, and for almost all other targets it is a colon.
CPATH specifies a list of directories to be searched as if specified with -I , but after any paths given with -I options on the command line. This environment variable is used regardless of which language is being preprocessed.
The remaining environment variables apply only when preprocessing the particular language indicated. Each specifies a list of directories to be searched as if specified with -isystem , but after any paths given with -isystem options on the command line.
In all these variables, an empty element instructs the compiler to search its current working directory. Empty elements can appear at the beginning or end of a path. For instance, if the value of CPATH is :/special/include , that has the same effect as ‘ -I. -I/special/include ’.
If this variable is set, its value specifies how to output dependencies for Make based on the non-system header files processed by the compiler. System header files are ignored in the dependency output.
The value of DEPENDENCIES_OUTPUT can be just a file name, in which case the Make rules are written to that file, guessing the target name from the source file name. Or the value can have the form ‘ file target ’, in which case the rules are written to file file using target as the target name.
In other words, this environment variable is equivalent to combining the options -MM and -MF (see Preprocessor Options), with an optional -MT switch too.
This variable is the same as DEPENDENCIES_OUTPUT (see above), except that system header files are not ignored, so it implies -M rather than -MM . However, the dependence on the main input file is omitted. See Preprocessor Options.
If this variable is set, its value specifies a UNIX timestamp to be used in replacement of the current date and time in the __DATE__ and __TIME__ macros, so that the embedded timestamps become reproducible.
The value of SOURCE_DATE_EPOCH must be a UNIX timestamp, defined as the number of seconds (excluding leap seconds) since 01 Jan 1970 00:00:00 represented in ASCII; identical to the output of date +%s on GNU/Linux and other systems that support the %s extension in the date command.
The value should be a known timestamp such as the last modification time of the source or package and it should be set by the build process.
Источник