Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2989,"date":"2020-01-09T19:34:10","date_gmt":"2020-01-09T19:34:10","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2989"},"modified":"2020-01-09T19:35:08","modified_gmt":"2020-01-09T19:35:08","slug":"how-to-install-gcc-on-centos-6","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/how-to-install-gcc-on-centos-6\/","title":{"rendered":"How To Install GCC on CentOS 6"},"content":{"rendered":"

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.<\/p>\n

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.<\/p>\n

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.<\/p>\n

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.<\/p>\n

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.<\/p>\n

Install an officially supported (older) version of GCC<\/h3>\n

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.<\/p>\n

    \n
  1. Login to your VPS, either by clicking “View Console” in the AKLWEB HOST control panel, or by SSH, if you have set that up.(a) Login as root.\n

    (b) Create your own user account, and give it a password.<\/p>\n

    adduser <username>\r\npasswd <username>\r\n<\/code><\/pre>\n

    (c) Allow your user account to execute commands with root privileges, through the sudo command.<\/p>\n

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

    (d) Log out as root, and login to your user account.<\/li>\n

  2. Install the CentOS 6 GCC packages. This will ask you if you want to install around 11 packages, due to dependencies.\n
    sudo yum install gcc gcc-c++\r\n<\/code><\/pre>\n<\/li>\n
  3. Check the installed versions, and show their locations.\n
    gcc --version\r\n    May say: gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)\r\ng++ --version\r\n    May say: g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)\r\nwhich gcc\r\n    \/usr\/bin\/gcc\r\nwhich g++\r\n    \/usr\/bin\/g++\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n

    Install a newer version of GCC from source<\/h3>\n

    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.<\/p>\n

      \n
    1. IMPORTANT!<\/strong>\u00a0First, complete the steps above to install an older binary version of GCC.<\/li>\n
    2. Install additionally required packages. This will ask you if you want to install around 41 packages.\n
      sudo yum install svn texinfo-tex flex zip libgcc.i686 glibc-devel.i686\r\n<\/code><\/pre>\n<\/li>\n
    3. Decide which version of GCC you want to install. This command will show you the “tags” for each of the versions available.\n
      svn ls svn:\/\/gcc.gnu.org\/svn\/gcc\/tags | grep gcc | grep release\r\n    gcc-2_95-release\/\r\n    ...\r\n    gcc-4_9_2_release\/\r\n    gcc-5_1_0_release\/\r\n<\/code><\/pre>\n<\/li>\n
    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\u00a0gcc-5_1_0_release\/<\/code>\u00a0and will download the sources into\u00a0~\/sourceInstallations\/gcc_5_1_0_release\/<\/code>.\n
      mkdir ~\/sourceInstallations\r\ncd ~\/sourceInstallations\r\nsvn co svn:\/\/gcc.gnu.org\/svn\/gcc\/tags\/gcc_5_1_0_release\/\r\n<\/code><\/pre>\n<\/li>\n
    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.\n
      cd gcc_5_1_0_release\/\r\n.\/contrib\/download_prerequisites\r\n    --- Important, run this as shown, from the gcc_5_1_0_release directory.\r\n    ---   Do not cd to the contrib directory\r\n<\/code><\/pre>\n<\/li>\n
    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.\n
      SWAP=\/tmp\/swap\r\ndd if=\/dev\/zero of=$SWAP bs=1M count=500\r\nmkswap $SWAP\r\nsudo swapon $SWAP\r\n<\/code><\/pre>\n<\/li>\n
    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.\n
      cd ..\r\nmkdir gcc_5_1_0_release_build\/\r\ncd gcc_5_1_0_release_build\/\r\n..\/gcc_5_1_0_release\/configure && make && sudo make install && echo \"success\"\r\n--- If your VPS has multiple cores, you can speed up the build by changing the middle part\r\n---   of this line from \"&& make &&\" to \"&& make -j <number of cores> &&\".\r\n--- You can see the number of cores your VPS has by running \"nproc\"\r\n<\/code><\/pre>\n<\/li>\n
    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.\n
      sudo swapoff $SWAP\r\nrm \/tmp\/swap\r\n<\/code><\/pre>\n<\/li>\n
    9. Check the installed versions, and see their locations.\n
      hash -r\r\n    (Makes your login \"forget\" about the previously seen locations of gcc and g++)\r\ngcc --version\r\n    May say: gcc (GCC) 5.1.0\r\ng++ --version\r\n    May say: g++ (GCC) 5.1.0\r\nwhich gcc\r\n    \/usr\/local\/bin\/gcc\r\nwhich g++\r\n    \/usr\/local\/bin\/g++\r\n<\/code><\/pre>\n<\/li>\n
    10. Add the new libraries to ld (the GNU linker).\n
      echo \"\/usr\/local\/lib64\" > usrLocalLib64.conf\r\nsudo mv usrLocalLib64.conf \/etc\/ld.so.conf.d\/\r\nsudo ldconfig\r\n    --- This may say a file or two \"is not an ELF file - it has the wrong magic bytes at the start.\"\r\n    --- You may ignore this message.  It is silent about the work it successfully completed.\r\n<\/code><\/pre>\n<\/li>\n
    11. Optionally make a hello world program.\n
      mkdir ~\/code\r\ncd ~\/code\r\nCreate a file main.cpp that says:\r\n    #include <iostream>\r\n    using namespace std;\r\n    int main() {\r\n        cout << \"Hello world!\" << endl;\r\n        return 0;\r\n    }\r\n--- One way to create this file is to run \"vi main.cpp\", hitting \"i\" to enter insert mode,\r\n---   typing the above file, hitting ESC, and hitting \"ZZ\" to save.\r\ng++ main.cpp -o main\r\n.\/main\r\n    Hello World!\r\n<\/code><\/pre>\n<\/li>\n
    12. Optionally reclaim hard drive space. Your\u00a0~\/sourceInstallations<\/code>\u00a0folder 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\u00a0sudo make install<\/code>\u00a0earlier, 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.\n
      cd ~\/\r\nrm -rf sourceInstallations\r\n--- Again, if you can spare the space, you may someday be happy to have left it there.\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n

      You now have your CentOS officially supported\u00a0gcc<\/code>\u00a0and\u00a0g++<\/code>\u00a0still in\u00a0\/usr\/bin\/<\/code>, your CentOS officially supported 32-bit libs in\u00a0\/lib<\/code>, your CentOS officially supported 64-bit libs in\u00a0\/lib64<\/code>, and your CentOS officially supported include files in\u00a0\/usr\/include<\/code>.<\/p>\n

      Your newer\u00a0gcc<\/code>\u00a0and\u00a0g++<\/code>\u00a0are in\u00a0\/usr\/local\/bin<\/code>, newer 32-bit libs in\u00a0\/usr\/local\/lib<\/code>, your newer 64-bit libs in\u00a0\/usr\/local\/lib64<\/code>, and your newer include files in\u00a0\/usr\/local\/include<\/code>.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[231,242],"manual_kb_tag":[487],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2989"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2989"}],"version-history":[{"count":3,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2989\/revisions"}],"predecessor-version":[{"id":2992,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2989\/revisions\/2992"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2989"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2989"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}