{"id":1025,"date":"2016-10-24T22:14:29","date_gmt":"2016-10-24T20:14:29","guid":{"rendered":"http:\/\/hobbykeller.spdns.de\/?p=1025"},"modified":"2016-10-24T22:14:29","modified_gmt":"2016-10-24T20:14:29","slug":"latest-gcc-compiler-on-ubuntu","status":"publish","type":"post","link":"https:\/\/hobbykeller.spdns.de\/?p=1025","title":{"rendered":"Latest gcc compiler on Ubuntu"},"content":{"rendered":"<p>I recently had some trouble compiling source code from the net which would not run under Ubuntu&#8217;s default gcc version, which is 5.4.0 for Xenial. The first thing to know is where to get the most recent gcc version, the second problem is how to tell Ubuntu (and the IDEs you are running) which of the gcc versions installed should be used.<\/p>\n<p><!--more--><\/p>\n<h1>Getting the latest gcc<\/h1>\n<p>You can read how to get the latest gcc in this post. The good news is: You don&#8217;t have to build it yourself, there is a ppa. Just type<\/p>\n<pre class=\"lang:default decode:true \" title=\"Installing the latest gcc\">ilek@i7:~$ sudo add-apt-repository ppa:ubuntu-toolchain-r\/test\r\nilek@i7:~$ sudo apt-get install gcc-6 g++-6\r\n\r\n<\/pre>\n<p>In my case, this triggered a whopping 500 MB download. So lean back and let apt do its work.<\/p>\n<h1>Setting the default version for gcc<\/h1>\n<p>Installing the gcc compiler alone won&#8217;t get you far. The reason is that unlike with updating some standard application like VirtualBox, the installation does not replace the old version by the new one but it installs the new version along the existing one(s). This however means that even if you have a more recent version installed, Ubuntu and your IDE will revert to the old version as your existing one.<\/p>\n<p>You can easily see that Ubuntu still reverts to the old 5.4.0 version after the installation:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Checking you gcc version\">ilek@i7:~$ g++ --version\r\ng++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609\r\nCopyright (C) 2015 Free Software Foundation, Inc.\r\nThis is free software; see the source for copying conditions.  There is NO\r\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r\n<\/pre>\n<p>As you can see, Ubuntu still invokes its default 5.4.0 version although the latest version 6 compiler is already installed. You can set the new default version with the update-alternatives command as described in <a href=\"http:\/\/askubuntu.com\/questions\/26498\/choose-gcc-and-g-version\" target=\"_blank\">this post<\/a>.<\/p>\n<p>We start with removing any alternative instructions:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Erasing the current update alternatives setup\">sudo update-alternatives --remove-all gcc \r\nsudo update-alternatives --remove-all g++<\/pre>\n<p>We now establish a new update-alternatives &#8220;hierarchy&#8221;:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Creating symbolic links with update-alternatives\">sudo update-alternatives --install \/usr\/bin\/gcc gcc \/usr\/bin\/gcc-5 10\r\nsudo update-alternatives --install \/usr\/bin\/gcc gcc \/usr\/bin\/gcc-6 20\r\n\r\nsudo update-alternatives --install \/usr\/bin\/g++ g++ \/usr\/bin\/g++-5 10\r\nsudo update-alternatives --install \/usr\/bin\/g++ g++ \/usr\/bin\/g++-6 20\r\n\r\nsudo update-alternatives --install \/usr\/bin\/cc cc \/usr\/bin\/gcc 30\r\nsudo update-alternatives --set cc \/usr\/bin\/gcc\r\n\r\nsudo update-alternatives --install \/usr\/bin\/c++ c++ \/usr\/bin\/g++ 30\r\nsudo update-alternatives --set c++ \/usr\/bin\/g++<\/pre>\n<p>When installing cc and c++ you may get an warning saying that update-alternatives is forcing the installation of <code>\/usr\/bin\/g++<\/code> because link group c++ is broken (or equivalent for cc). Don&#8217;t worry, it just means that update-alternatives has so far not produced any corresponding symlink into <code>\/usr\/bin\/<\/code> and it will produce that symlink now.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently had some trouble compiling source code from the net which would not run under Ubuntu&#8217;s default gcc version, which is 5.4.0 for Xenial. The first thing to know<span class=\"more-button\"><a href=\"https:\/\/hobbykeller.spdns.de\/?p=1025\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">Latest gcc compiler on Ubuntu<\/span><\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[228,227,229],"class_list":["post-1025","post","type-post","status-publish","format-standard","hentry","category-linux","tag-g-gcc-latest","tag-gcc","tag-ubuntu-toolchain-rtest"],"_links":{"self":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1025"}],"version-history":[{"count":1,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1025\/revisions"}],"predecessor-version":[{"id":1026,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1025\/revisions\/1026"}],"wp:attachment":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}