How VPS - How to use/setup VPS
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System CentOS

How To Install GCC on CentOS 6

How VPS by How VPS
October 1, 2019
in CentOS
0
0
SHARES
20
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Install an officially supported (older) version of GCC
  2. Install a newer version of GCC from source
  3. Want to contribute?


CentOS follows the development of Red Hat Enterprise Linux (RHEL). RHEL strives to be a stable server platform, which means that it does not rush to include the latest versions of every software package.

As of the writing of this article, CentOS 6 officially distributes GCC v4.4.7. However, GCC v5.1 was recently released. Before that, v4.9.2 was available.

The official suggestion to needing a more recent version of GCC is that you should consider a different UNIX distribution which is more focused on supporting the latest versions of software packages.

Fortunately, you are able to install a more recent version of GCC on CentOS, leaving the older version still installed. This deviates from purely using the officially distributed software, but sometimes you may feel like you have little choice. You can run into some complications; for example, if you are installing third party kernel modules, they must be compiled using the same version of GCC used to build your kernel.

This article describes how to install the CentOS 6 officially supported version of GCC, and how to install a newer version as well. This article assumes that you have a freshly installed CentOS 6 VPS, although you can certainly follow the instructions on an existing VPS.

Install an officially supported (older) version of GCC

Even if you want to install a newer version of GCC from source, GCC itself is written in C++. Therefore, you first have to install an older C++ compiler.

  1. Login to your VPS, either by clicking “View Console” in the Vultr control panel, or by SSH, if you have set that up.

    (a) Login as root.

    (b) Create your own user account, and give it a password.

    adduser <username>
    passwd <username>
    

    (c) Allow your user account to execute commands with root privileges, through the sudo command.

    visudo
        After the line "root   ALL=(ALL)   ALL"
        Add the line "<username>   ALL=(ALL)   ALL"
        --- If you aren't familiar with vi, go to the line "root   ALL=(ALL)   ALL".
        ---   Hit "o" to create a new line after that line and enter insert mode.
        ---   Type "<username>   ALL=(ALL)   ALL".
        ---   Hit ESC.
        ---   Type "ZZ" to save.
    

    (d) Log out as root, and login to your user account.

  2. Install the CentOS 6 GCC packages. This will ask you if you want to install around 11 packages, due to dependencies.

    sudo yum install gcc gcc-c++
    
  3. Check the installed versions, and show their 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++
    

Install a newer version of GCC from source

If you only want the CentOS officially supported version of GCC, you’re all set. If you need a more recent version of GCC, continue on.

  1. IMPORTANT! First, complete the steps above to install an older binary version of GCC.

  2. Install additionally required packages. This will ask you if you want to install around 41 packages.

    sudo yum install svn texinfo-tex flex zip libgcc.i686 glibc-devel.i686
    
  3. Decide which version of GCC you want to install. This command will show you the “tags” for each of the versions available.

    svn ls svn://gcc.gnu.org/svn/gcc/tags | grep gcc | grep release
        gcc-2_95-release/
        ...
        gcc-4_9_2_release/
        gcc-5_1_0_release/
    
  4. Get the source of the version of GCC you want. This will run for a few minutes. The rest of this article is written for gcc-5_1_0_release/ and will download the sources into ~/sourceInstallations/gcc_5_1_0_release/.

    mkdir ~/sourceInstallations
    cd ~/sourceInstallations
    svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_5_1_0_release/
    
  5. Get the source of additional prerequisites. Using v5.1.0, this downloads sources and adds them to the GCC build for MPFR v2.4.2, GMP 4.3.2, and MPC 0.8.1.

    cd gcc_5_1_0_release/
    ./contrib/download_prerequisites
        --- Important, run this as shown, from the gcc_5_1_0_release directory.
        ---   Do not cd to the contrib directory
    
  6. If your VPS only has 768MB of memory, you will run out of memory in the next step. If you have 1GB of memory, you may be OK, but it can’t hurt to do this step. If you have 2GB of memory, or more, you can skip this step. This step adds 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. Build GCC. This will run for hours. If this completes correctly, the last line you will see will say “success”. It is normal to see some error-looking messages scrolling by quickly, as long as the build completes and echos “success”. It’s always a good idea to build things in a different directory than a source directory. GCC documentation states that you should not use a build directory that is a sub-directory of the source directory.

    cd ..
    mkdir gcc_5_1_0_release_build/
    cd gcc_5_1_0_release_build/
    ../gcc_5_1_0_release/configure && make && sudo make install && echo "success"
    --- If your VPS has multiple cores, you can speed up the build by changing the middle part
    ---   of this line from "&& make &&" to "&& make -j <number of cores> &&".
    --- You can see the number of cores your VPS has by running "nproc"
    
  8. If you set up a swap file in step 6, remove it. Without doing more configuring, after a reboot, it won’t be used as a swap file, and just take up hard drive space in your VPS.

    sudo swapoff $SWAP
    rm /tmp/swap
    
  9. Check the installed versions, and see their locations.

    hash -r
        (Makes your login "forget" about the previously seen locations of gcc and g++)
    gcc --version
        May say: gcc (GCC) 5.1.0
    g++ --version
        May say: g++ (GCC) 5.1.0
    which gcc
        /usr/local/bin/gcc
    which g++
        /usr/local/bin/g++
    
  10. Add the 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. Optionally make a hello world program.

    mkdir ~/code
    cd ~/code
    Create a file main.cpp that says:
        #include <iostream>
        using namespace std;
        int main() {
            cout << "Hello world!" << endl;
            return 0;
        }
    --- One way to create this file is to run "vi main.cpp", hitting "i" to enter insert mode,
    ---   typing the above file, hitting ESC, and hitting "ZZ" to save.
    g++ main.cpp -o main
    ./main
        Hello World!
    
  12. Optionally reclaim hard drive space. Your ~/sourceInstallations folder will be taking up around 8.0GB. It’s probably wise to keep the folders, as there are optional configuration options you may need to use at some point in the future, and it would be faster to have a lot already done. Also, the build process makes logs that you can later check and work from if something goes wrong. But, after running sudo make install earlier, your installed GCC isn’t depending on anything in this directory, and space can be at a premium, so you can do this step and reclaim the 8.0GB or so.

    cd ~/
    rm -rf sourceInstallations
    --- Again, if you can spare the space, you may someday be happy to have left it there.
    

You now have your CentOS officially supported gcc and g++ still in /usr/bin/, your CentOS officially supported 32-bit libs in /lib, your CentOS officially supported 64-bit libs in /lib64, and your CentOS officially supported include files in /usr/include.

Your newer gcc and g++ are in /usr/local/bin, newer 32-bit libs in /usr/local/lib, your newer 64-bit libs in /usr/local/lib64, and your newer include files in /usr/local/include.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
How VPS

How VPS

Related Posts

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Install BoltWire CMS on CentOS 7
CentOS

How to Install BoltWire CMS on CentOS 7

February 14, 2020
Showterm.io – A Terminal/Shell Recording, Upload and Share Tool for Linux
CentOS

Setup HTTP Authentication With Nginx on CentOS 7

February 14, 2020
Next Post

How to Install ProcessWire CMS 3.0 on a CentOS 7 LAMP VPS

How to Install OpenNMS on CentOS 7

How to Install Craft CMS on CentOS 7

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

  • 121 Followers
  • 87.2k Followers

Recommended

Bat – A Cat Clone with Syntax Highlighting and Git Integration

4 years ago

How to Install Mailtrain Newsletter Application on FreeBSD 12

4 years ago

How to Disable SELinux on CentOS 7

3 years ago

How to Install Redaxscript 3.2 CMS on a Debian 9 LAMP VPS

3 years ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

Topics

Apache Web Server Bluehost Review 2019 Bluehost Review 2020 Bluehost Review 2021 Centmin Mod CentminMod centos install htop fsck htop install HTTP DoS attack Install Snort on an Ubuntu install Zabbix on CentOS install Zabbix on CentOS 7 Linux Commands linux guide linux install htop linux vps setup guide MariaDB MariaDB Error Mysql mysqld error optimize MariaDB optimize Mysql snort Ubuntu
No Result
View All Result

Highlights

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Webmin Reviews

Virtualmin Reviews

CentOS Web Panel Reviews

Ajenti Reviews

ISPConfig Reviews

Trending

Failed to download metadata for repo 'appstream' on Centos 8
CentOS

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

by How VPS
February 25, 2022
0

I tried to update some extensions by use yum on centOs which I specified in Dockerfile. After...

How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020
Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

Top Free Web Hosting Control Panels To Manage VPS/Dedicated Servers

February 17, 2020
Webmin Reviews

Webmin Reviews

February 17, 2020
How VPS – How to use/setup VPS

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Visit our landing page to see all features & demos.
LEARN MORE »

Recent News

  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8 February 25, 2022
  • How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”? November 17, 2020
  • How to optimize Mysql or MariaDB November 3, 2020

Categories

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel

[mc4wp_form]

© 2018 JNews - City News Magazine WordPress theme. All rights belong to their respective owners.
JNews is a top selling 2018 WordPress News, Blog, Newspaper & Magazine Theme.

No Result
View All Result
  • Home

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.