Archive

How to install and update GCC on Centos 7

I will show you How to install and update GCC on Centos 7 step by step. Just follow my steps and if you get any error just comment on this post i will reply as soon as possible.

If your centos 7 is freshly installed you need to update our centos 7.

yum update

After that just install some basic requirements that will be needed nex steps.

yum install bzip2
yum install wget
yum install nano

How to install GCC on Centos 7

Just follow same steps as centos 6 and compile GCC on your machine. You must made a change for centos 7. Only one difference is at 7 step when you are compiling GCC.

Adjust your command as your need :

../gcc-6.1.0/configure –enable-languages=c,c++ –disable-multilib && make -j <number of CPU cores> && sudo make install && echo “success”

you have too add these paramaters : –enable-languages=c,c++ –disable-multilib

Other step as same as follows

How To Install Newer Version Of GCC on CentOS 6.x

 

How to solve GLIBCXX Not Found Error on Centos 7

 

Just follow these steps (You must compile newer version of GCC):

cd /usr/local/lib64
cp libstdc++.so.6.0.22 /usr/lib64/
cd /usr/lib64/
mv libstdc++.so.6 libstdc++.so.6.OLD
ln -sf libstdc++.so.6.0.22 libstdc++.so.6

This will solve these problems :

libstdc++.so.6 not found CentOS 7.3
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21′ not found

 

Lets Check :

strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

Output :

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22

How to Update glibc Newer Version on Centos 6.x

You tried to runs some commands and got error about your glibc version is not high enough to complete your command. Thus, You may need newer version glibc on your Centos 6.x VPS server. I will show you how to update glibc.

How to Update glibc Newer Version on Centos 6.x

We have two way to accomplish this task. One way is that compile from source which take too long time to do that. Another way is that get files from repo which is relatively easy step.

Lets first check our glibc versions that installed in our VPS server:

strings /lib64/libc.so.6 | grep GLIBC

Result:

GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12

 

1.  Compile glibc From Source

We can get soruce file in 2 ways, using git or ftp. You can get latest version from git. We need GLIBC_2.17 version for our centos 6.x so we will use ftp.

mkdir ~/glibc-install; cd ~/glibc-install
wget http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz
tar -zxvf glibc-2.17.tar.gz

After Download and extract all source files we need to create a build folder. It is better way to have another folder for build.

cd glibc-2.17
mkdir build

We need to put files  separete place in order to not corrput our linux system. /opt/glibc-2.17

cd build
../configure --prefix=/opt/glibc-2.17

We can start compiling our source files. It will take hours depending your CPU cores. You can find your <number of CPU Cores> by using nproc command.

make -j<number of CPU Cores>
make install

After compiling is done we need to show place of our new glibc to program we are gonna use. In order to do that follow step below;

 

LD_LIBRARY_PATH=/opt/glibc-2.17/lib

export LD_LIBRARY_PATH.

Furing your current login session on VPS Library is exposed

Another way is that creating symbolic link :

ln -sf /opt/glibc-2.17/glibc-2.17.so /lib/libc.so.6.

I do not recommend this step because linux use older version of glibc and if you create a symbolic link somethings will sure go wrong.

If you are not experienced system administrator do not play with glibc, it might break your Linux system.

2. Using RPM to install new version of glibc

Update glibc to 2.17 for CentOS 6

I found a script from github. We will use it. Lets appreciated his work : https://gist.github.com/harv/f86690fcad94f655906ee9e37c85b174

Script :


#! /bin/sh

# update glibc to 2.17 for CentOS 6

wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-2.17-55.el6.x86_64.rpm
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-common-2.17-55.el6.x86_64.rpm
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-devel-2.17-55.el6.x86_64.rpm
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-headers-2.17-55.el6.x86_64.rpm

sudo rpm -Uvh glibc-2.17-55.el6.x86_64.rpm \
glibc-common-2.17-55.el6.x86_64.rpm \
glibc-devel-2.17-55.el6.x86_64.rpm \
glibc-headers-2.17-55.el6.x86_64.rpm

You might ecounter some errors: “error: Failed dependencies:

To fix it just add this parameter --force --nodeps at the end of the all command.

After finished up lets check again :

strings /lib64/libc.so.6 | grep GLIBC

Result :

GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_PRIVATE

We have GLIBC_2.17 on our centos 6.x VPS server.

If you have a question just post as a comment and i will reply it as soon as possible.

GLIBCXX_3.4.xx Not Found – Install Newer Version Of GLIBCXX on Centos 6

Centos 6.x user might face it the GLIBCXX version error on their VPS server. You can solve this error switching your OS version to more newer ones like centos 7.x. However, if you want to stick with centos 6.x and have newer version of GLIBCXX just follow steps i will show on this article.

 

GLIBCXX_3.4.xx Not Found Error means that version on your Cenots 6.x VPS machine is not high enough to run the binary. Thus we will need  to upgrade GLIBCXX version.

Lets first check our Centos 6.x VPS’s GLIBCXX versions.

strings /usr/lib64/libstdc++.so.6 | grep GLIBC

Here is the result:

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_FORCE_Yeni
GLIBCXX_DEBUG_MESSAGE_LENGTH

We need more newer version to run our programs on centos 6.x.

Fixing  /lib/libstdc++.so.6: version GLIBCXX_3.4.xx not found Error

We need libstdc++.so.6.0.22 file in order to have higer version of GLIBCXX. You can create the file by following the steps from this article : How To Install Newer Version Of GCC on CentOS 6.x

After you created libstdc++.so.6.0.22 file just follow these steps :

cd /usr/local/lib64
cp libstdc++.so.6.0.22 /usr/lib64/
cd /usr/lib64/
mv libstdc++.so.6 libstdc++.so.6.OLD
ln -sf libstdc++.so.6.0.22 libstdc++.so.6

Lets check GLIBCXX versions again:

strings /usr/lib64/libstdc++.so.6 | grep GLIBC

Result :

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBC_2.3
GLIBC_2.2.5
GLIBC_2.3.2
GLIBCXX_FORCE_Yeni
GLIBCXX_DEBUG_MESSAGE_LENGTH

We have new version of GLIBCXX on our centos 6.x VPS server now. You can try to run your program and check that you are not getting same error anymore.

 

If you have any question just write a comment and i will reply as soon as possible.

How To Install Newer Version Of GCC on CentOS 6.x

 
 
You might encounter GCC libraries erros that stated you use older  version of gcc or you need newer version of gcc in some cases to run some programs on CentOS 6 system.

I will show you How To Install Newer Version Of GCC on CentOS 6.x

You have to compile new gcc version on your linux machine. I suggest you to use a server that has more than 4 cpu because compiling gcc takes hours if you have limited cpu on your server. In addition to cpu number importance, you need a more than 20gb free space for compiling gcc. Please take account these suggestions.

As of the writing of this article, centos 6.x use GCC v4.4.7 version and latest GCC v7.3 released. You can install any version on your VPS server.

How To Install GCC on CentOS 6.x

We will install older version of GCC from base repo on our VPS because we need C++ compiler in order to compile newer version on our VPS server

1. Login to your VPS

A. Login as a Root user
B. Create a user account and set a password for it
adduser <username>
passwd <username>

C. You have to give root privileges to your newly created user account
visudo
Find the line "root ALL=(ALL) ALL" and after that line
Add the line "<username> ALL=(ALL) ALL"
then Ctrl+C and write :wq and exit.

D. You can logou t from your root account and re-login with new accout that you gave root privileges

2. Install GCC packages on your Centos 6.x VPS.
sudo yum install gcc gcc-c++

3. After install, Check GCC versions and locations.
gcc --version
May say: gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
g++ --version
May say: g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
which gcc
/usr/bin/gcc
which g++
/usr/bin/g++

How To Install Newer Version Of GCC on CentOS 6.x

We installed officially supported GCC version on our VPS but we want newer version so lets continue…

1. Be sure! you installed older version of GCC that we show you complete steps above. 

2. We need to install additionally required packages:
sudo yum install svn texinfo-tex flex zip libgcc.i686 glibc-devel.i686

3. We can decide which version of GCC we are gonna compile and use our VPS. This command will show you all availabe versions GCC :
svn ls svn://gcc.gnu.org/svn/gcc/tags | grep gcc | grep release

gcc_6_1_0_release/
gcc_6_2_0_release/
gcc_6_3_0_release/
gcc_6_4_0_release/
gcc_7_1_0_release/
gcc_7_2_0_release/
gcc_7_3_0_release/

4. We decided to compile GCC 6.1 version. This steps could takes few minutes depending on your internet connection. This article is written for gcc_6_1_0_release/ so please be careful while copying our code if you decided to install different version.
mkdir ~/GCC-source
cd ~/GCC-source
svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_6_1_0_release/

5. After getting all files, lets install source of additional prerequisites. It will install MPFR, GMP , and MPC on your VPS. Run this command inside of the source files.
cd gcc_6_1_0_release/
./contrib/download_prerequisites
--- Important, run this as shown, from the gcc_6_1_0_release directory.
--- Do not! cd to the contrib directory or you get errors

6. compiling use great amount of memory so if you have a memory lower than 1GB on your VPS server we suggest you to follow these steps. However, If you have more than 2GB you can skip this step. This step add 500MB of virtual memory, using a swap file.
SWAP=/tmp/swap
dd if=/dev/zero of=$SWAP bs=1M count=500
mkswap $SWAP
sudo swapon $SWAP

7. We are building ! This could take hours depending on how man cpu you have. If this thing goes smoothly we will see “finished” as a last line. It is normal to see some error like messages. We will use different directory to compile this because it is better way to do it.
cd ..
mkdir gcc_6_1_0_release-build/
cd gcc_6_1_0_release-build/
../gcc_6_1_0_release-build/configure && make && sudo make install && echo "finished"
--- If your VPS has multiple CPU cores, you can speed up this progress by changing the middle part of the code
--- change line from "&& make &&" to "&& make -j <number of CPU cores> &&".
--- You can see how many CPU cores your VPS has by running this code "nproc"

8. If you followed the instructions at 6. steps remove the swap file.
sudo swapoff $SWAP
rm /tmp/swap

9. Lets check installed versions and their locations
hash -r
(Makes your login "forget" about the previously seen locations of gcc and g++)
gcc --version
May say: gcc (GCC) 6.1.0
g++ --version
May say: g++ (GCC) 6.1.0
which gcc
/usr/local/bin/gcc
which g++
/usr/local/bin/g++

10. We need to add new libraries to ld (the GNU linker).
echo "/usr/local/lib64" > usrLocalLib64.conf
sudo mv usrLocalLib64.conf /etc/ld.so.conf.d/
sudo ldconfig
--- This may say a file or two "is not an ELF file - it has the wrong magic bytes at the start."
--- You may ignore this message. It is silent about the work it successfully completed.

11. After we compiling newer version of GCC, our GCC-source folder size is over 8.0GB or so. We can keep this folder in case of need in future. However, if you need space you can reclaim this space.

cd ~/
rm -rf GCC-source

Yes, we have newer version of GCC on our centos 6.x VPS now.

CentOS officially supported GCC versions can be found in /usr/bin/ and include files in /usr/include

You newer GCC version files can be found in : /usr/local/bin  newer 32-bit libs in  /usr/local/lib newer 64-bit libs in /usr/local/lib64 newer include files in /usr/local/include

Lets point out some other issues that Centos 6.x users face and solve with it newly compiled GCC versions :  GLIBCXX_3.4.xx Not Found – Install Newer Version Of GLIBCXX on Centos 6