What would be the easiest way to install gcc
4.7.x/4.8.x on a system with CentOS 6.2+? The default RPM package contains an older version of gcc
.
Centos – How tonstall gcc 4.7.x/4.8.x on CentOS
centosrpmyum
Related Solutions
Let us assume the ISO is already burnt into a DVD, or the ISO is present as a file on your file system. First, we need to mount it. The preferred mount point to mount it is /media/CentOS
, because yum
is configured to look for repositories from this location by default while installing packages from DVD. The steps below describe how to mount the ISO (whether present as a file or burnt into DVD) and install packages from the ISO.
- If you have the ISO burnt into a DVD, insert the DVD into the CentOS system. If the ISO is not burnt into a DVD, but present as a separate file on the file system, then skip the next two steps and go directly to step 4 in this list.
Check if the DVD has been mounted automatically. To do this execute the following command:
mount | grep CentOS
If this command returns an output, it means the DVD has been mounted. For example, the following example output shows that the DVD has been mounted to
/media/CentOS_6.4_Final
automatically./dev/sr0 on /media/CentOS_6.4_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,iocharset=utf8,mode=0400,dmode=0500)
If the CD has been mounted automatically, then ignore this step. Otherwise, mount it manually.
mkdir /media/CentOS mount -t iso9660 /dev/sr0 /media/CentOS
If the ISO is present on the file system, mount it to
/media/CentOS
using themount
command with-o loop
option.mount -o loop CentOS-6.4-x86_64-bin-DVD1.iso /media/CentOS/
Execute:
cat /etc/yum.repos.d/CentOS-Media.repo
and read the information provided as comments in this file. See the repo name within square brackets. It isc6-media
by default. Also, see the locations specified forbaseurl
property. These URLs point to local directories/media/CentOS
,/media/cdrom
and/media/cdrecorder/
by default.If the DVD is mounted to a mount point specified in the
baseurl
property, then ignore this step. Otherwise, create a symbolic link at a location specified in thebaseurl
property with the mount point as its target. An example follows.ln -s /media/CentOS_6.4_Final /media/CentOS
In the shell, execute the
yum
command while disabling all repos except the repo specified in/etc/yum.repos.d/CentOS-Media.repo
:yum --disablerepo=\* --enablerepo=c6-media install gcc
I don't think it's possible to install GCC-5 on CentOS 5, its glibc
version (2.5) is way too old.
For CentOS 6, use the following instructions:
- http://en.librehat.com/blog/build-gcc-5-dot-2-on-rhel-6/
- http://www.linuxfromscratch.org/blfs/view/cvs/general/gcc.html
Or you can use Docker with the following Dockerfile:
FROM centos:centos6
RUN yum install -y gcc gcc-c++ wget xz libgcc glibc-devel glibc-headers
# Run some tests
RUN gcc --version && \
g++ --version && \
which gcc && \
which g++
RUN mkdir ~/tests && \
cd ~/tests && \
echo '#include <iostream>' > main.cpp && \
echo 'using namespace std;' >> main.cpp && \
echo 'int main() {' >> main.cpp && \
echo ' cout << "Hello world!" << endl;' >> main.cpp && \
echo ' return 0;' >> main.cpp && \
echo '}' >> main.cpp && \
g++ main.cpp -o main && \
./main
# Download and compile GCC-5
# http://en.librehat.com/blog/build-gcc-5-dot-2-on-rhel-6/
# Download and extract source code
ENV gcc_version "5.3.0"
RUN wget --no-verbose \
http://ftpmirror.gnu.org/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2 && \
tar xf gcc-${gcc_version}.tar.bz2
RUN wget --no-verbose \
https://gmplib.org/download/gmp/gmp-6.1.0.tar.xz && \
tar xf gmp-6.1.0.tar.xz && \
mv gmp-6.1.0 gcc-${gcc_version}/gmp
RUN wget --no-verbose \
ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz && \
tar xf mpc-1.0.3.tar.gz && \
mv mpc-1.0.3 gcc-${gcc_version}/mpc
RUN wget --no-verbose \
http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.xz && \
tar xf mpfr-3.1.4.tar.xz && \
mv mpfr-3.1.4 gcc-${gcc_version}/mpfr
# Compile and install GCC
# "we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree"
RUN mkdir gcc-${gcc_version}_build && \
cd gcc-${gcc_version}_build && \
../gcc-${gcc_version}/configure \
--prefix=/usr \
--disable-multilib \
--enable-languages=c,c++ \
--enable-libstdcxx-threads \
--enable-libstdcxx-time \
--enable-shared \
--enable-__cxa_atexit \
--disable-libunwind-exceptions \
--disable-libada \
--host x86_64-redhat-linux-gnu \
--build x86_64-redhat-linux-gnu \
--with-default-libstdcxx-abi=gcc4-compatible
RUN cd gcc-${gcc_version}_build && make -j4
RUN cd gcc-${gcc_version}_build && make install
# Validate the installed compiler
RUN hash -r && \
gcc --version && \
g++ --version && \
which gcc && \
which g++
# Register new libraries with `ldconfig`
RUN echo "/usr/local/lib64" > usrLocalLib64.conf && \
mv usrLocalLib64.conf /etc/ld.so.conf.d/ && \
ldconfig
# Clean out all the garbage
RUN rm -rf ~/${gcc_release} ~/{gcc_release}_build ~/tests
Best Answer
Tru Huynh of centos.org has built the redhat developer toolset 1.1, for centos and it contains gcc 4.7.2
So you could simply use his repo and install just gcc, instantly.
This will install it most likely into
/opt/centos/devtoolset-1.1/root/usr/bin/
Then you can tell your compile process to use the gcc 4.7 instead of 4.4 with the CC variable