Compile and install GCC 5.2.0 in CentOS 6.6
Compiling C/C ++ programs in Linux naturally lacks an excellent compiler, and GCC is a common tool in Linux.
In 2015, GCC also came out of version 5.2.0, providing better support for C ++ 11/14.
So today we will talk about the GCC compilation and installation. The installed version is the latest version 5.2.0.
Next let's go to the topic (we suggest using the root user throughout the process ):
1. Download the GCC source code:
Wget ftp://mirrors.kernel.org/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.gz
2. decompress:
Tar-zxvf gcc-5.2.0.tar.gz
3. download the required dependencies for compilation:
Cd gcc-5.2.0 // enter the gcc folder after unpacking
./Contrib/download_prerequisites // download Dependencies
Cd .. // return to the upper directory
4. Create a compilation output directory:
Mkdir gcc-build-5.2.0
5. Enter the output directory, execute the following command, and generate the makefile file:
Cd gcc-build-5.2.0
../Gcc-5.2.0/configure -- enable-checking = release -- enable-packages ages = c, c ++ -- disable-multilib
6. Compile:
Make-j4
The next step is to wait for about 40 minutes.
PS: it is best not to do anything in the compilation process. The CPU is fully loaded throughout the process,
If it is inexplicably terminated, there will be a lot of troubles in the future. Note that the remaining space in the current directory must be at least 4 GB during compilation; otherwise, compilation will fail.
7. installation:
After compilation, we can execute the installation:
Make install
8. Check the version:
Gcc -- version
Or gcc-v
7. Switch GCC to the new version to determine the path of the newly installed GCC, which is usually under/usr/local/bin by default.
You can first updatedb, then locate the gcc-4.8 | tail look for ls/usr/local/bin | grep gcc to add new GCC to the option,
The third to last parameter is the name, and the second to last parameter is the new GCC path. The last parameter 40 is the priority, and the new version is automatically used after it is set to a greater value.
Update-alternatives -- install/usr/bin/gcc x86_64-unknown-linux-gnu-gcc-5.2.0/usr/local/bin/x86_64-unknown-linux-gnu-gcc-5.2.0 40
Then, you need to delete the gcc file under the usr/bin/directory or avoid exceptions. you can name it gcc. bak.
Note that the usr/bin/gcc version is always used when you use gcc-v to view the current version.
The purpose of ln-s/usr/local/bin/x86_64-unknown-linux-gnu-gcc-5.2.0/usr/bin/gcc is to generate gcc version 5.2.
The complete steps are as follows:
Mv/usr/bin/gcc. bak
Ln-s/usr/local/bin/x86_64-unknown-linux-gnu-gcc-5.2.0/usr/bin/gcc
8. confirm that the current version has been switched to the new version of gcc-v. I am using ssh remotely here. I found that the version has not changed. I disconnected and retried it. After the session is regenerated, I found it changed to 5.2!
Linux GCC 4.8.1 clear and concise tutorial (Ubuntu 12.04 64-bit edition as an example)
Install and use Vim + GCC + GDB in Ubuntu
Switch two GCC versions in Ubuntu
CentOS6.5 upgrade to manually install GCC4.8.2
GCC details: click here
This article permanently updates the link address: