| These commands are based on a askubuntu answer http://askubuntu.com/a/581497 | |
| To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below. | |
| USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING. | |
| ABSOLUTELY NO WARRANTY. | |
| If you are still reading let's carry on with the code. | |
| sudo apt-get update && \ | |
| sudo apt-get install build-essential software-properties-common -y && \ | |
| sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \ | |
| sudo apt-get update && \ | |
| sudo apt-get install gcc-snapshot -y && \ | |
| sudo apt-get update && \ | |
| sudo apt-get install gcc-6 g++-6 -y && \ | |
| sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \ | |
| sudo apt-get install gcc-4.8 g++-4.8 -y && \ | |
| sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8; | |
| When completed, you must change to the gcc you want to work with by default. Type in your terminal: | |
| sudo update-alternatives --config gcc | |
| To verify if it worked. Just type in your terminal | |
| gcc -v | |
| If everything went fine you should see gcc 6.1.1 by the time I am writing this gist | |
| Happy coding! | |
| See my blog post at https://www.application2000.com |
This comment has been minimized.
This comment has been minimized.
|
worked perfectly thanks. |
This comment has been minimized.
This comment has been minimized.
|
Thank You |
This comment has been minimized.
This comment has been minimized.
g++-6 : Depends: gcc-6-base (= 6.1.1-2ubuntu12~16.04) but 6.1.1-3ubuntu11~14.04.1 is to be installed
Depends: libstdc++-6-dev (= 6.1.1-2ubuntu12~16.04) but it is not going to be installed
gcc-6 : Depends: cpp-6 (= 6.1.1-2ubuntu12~16.04) but it is not going to be installed
Depends: gcc-6-base (= 6.1.1-2ubuntu12~16.04) but 6.1.1-3ubuntu11~14.04.1 is to be installed
Depends: libgcc-6-dev (= 6.1.1-2ubuntu12~16.04) but it is not going to be installed
E: Unable to correct problems, you have held broken packages. |
This comment has been minimized.
This comment has been minimized.
|
This worked fine today. update-alternatives --config gcc Selection Path Priority Status
Press to keep the current choice[*], or type selection number:` Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Very helpful, thank you |
This comment has been minimized.
This comment has been minimized.
|
Thanks, worked great! I modified it slightly to keep the default 16.04 gcc-5 around: sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-snapshot -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
-sudo apt-get install gcc-4.8 g++-4.8 -y && \
-sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8;
+# Already installed gcc-5 as part of build-essential; I didn't need this line..
+# sudo apt-get install gcc-5 g++-5 -y && \
+sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5; |
This comment has been minimized.
This comment has been minimized.
|
Thanks. Worked perfectly. :) |
This comment has been minimized.
This comment has been minimized.
|
Hi, i am getting below error while trying to upgrade gcc, root@compute:/tmp# sudo apt-get update && \
please help me to short it out. |
This comment has been minimized.
This comment has been minimized.
|
root@compute:/tmp# update-alternatives --config gcc |
This comment has been minimized.
This comment has been minimized.
|
Good Stuff!! thank you worked great on Ubuntu 16.0.4 |
This comment has been minimized.
This comment has been minimized.
|
nice, just need it for clang 3.9 for Travis CI. |
This comment has been minimized.
This comment has been minimized.
|
Hash sum mismatches when running |
This comment has been minimized.
This comment has been minimized.
|
what does the '-y' at the end of the line? |
This comment has been minimized.
This comment has been minimized.
|
Nice, thank you very much |
This comment has been minimized.
This comment has been minimized.
|
the -y flag causes apt-get to assume "yes" when it would normally prompt you with a yes /no question |
This comment has been minimized.
This comment has been minimized.
|
This is great |
This comment has been minimized.
This comment has been minimized.
|
Work very well for me, I had problems after update my kernel version with vmware. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:
select gcc-9 |
This comment has been minimized.
This comment has been minimized.
|
Hopefully it could help someone. Take care and Have a nice day. Cheers. |
This comment has been minimized.
This comment has been minimized.
|
GCC 7.1 on Ubuntu 14.04 & 16.04:
|
This comment has been minimized.
This comment has been minimized.
|
Work very well for me. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
@peterhanneman Thank you for the update. Take care |
This comment has been minimized.
This comment has been minimized.
|
thank you ivanmara555 worked on 16.04 LTS.. |
This comment has been minimized.
This comment has been minimized.
|
thank you , this work very well ! |
This comment has been minimized.
This comment has been minimized.
|
Thank you! This works on Debian as well but instead of adding the Ubuntu repo you can add |
This comment has been minimized.
This comment has been minimized.
|
Thanks, this worked for me on Ubuntu 16.04. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the tip @1Forge. Thank you all for your comments. Hope it helps everybody. Happy coding! |
This comment has been minimized.
This comment has been minimized.
|
Thank you peterhanneman. Your one-liner worked perfectly. |
This comment has been minimized.
This comment has been minimized.
|
This is gold dust! Many thanks. |
This comment has been minimized.
This comment has been minimized.
|
Bro are you serious right now?! This worked like a fucking dream! |
This comment has been minimized.
This comment has been minimized.
|
Thank you, solved an issue on Ubuntu 17.04 |
This comment has been minimized.
This comment has been minimized.
|
Thank you very much. Upgraded from 5 to 6.3 |
This comment has been minimized.
This comment has been minimized.
|
Thanks, confirmed works on WSL Ubuntu 16.04 |
This comment has been minimized.
This comment has been minimized.
|
worked fine! Thanks a lot :) |
This comment has been minimized.
This comment has been minimized.
|
Excellent! Still works from 4.9.3 to 6.3! Very helpful thank you! |
This comment has been minimized.
This comment has been minimized.
|
excellent! thanks very much! |
This comment has been minimized.
This comment has been minimized.
|
Thank you! Such good directions. Worked like a charm. |
This comment has been minimized.
This comment has been minimized.
|
It works. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Thanks .Very helpfull !! |
This comment has been minimized.
This comment has been minimized.
|
This is not correct. if i type "sudo apt-get install gcc-6 g++-6 -y" command, it says "E: Unable to locate package gcc-6" and then "E: Unable to locate package g++-6" and then "E: Couldn't find any package by regex 'g++-6'". |
This comment has been minimized.
This comment has been minimized.
|
Thanks @peterhanneman! |
This comment has been minimized.
This comment has been minimized.
|
Great work. 4.8 worked fantastically to compile mysql-python 1.2.5. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Awesome walk through. In detail and no nonsense! Thank you |
This comment has been minimized.
This comment has been minimized.
|
Works great! Thanks. |
This comment has been minimized.
This comment has been minimized.
|
WARNING @application2000 @mdhanasar @GHnubsST @@AnanthanM @yech1990 @zxshoe @andrewrech @jwarlander @Sakib37 @ArulrajAnto @HungryHowies @AraHaan @KyCodeHuynh @S0ulR3av3R @talland @jasonbeach @smac89 @zheive @ivanmara555 @peterhanneman @toffyjan @k-five @hanzin @smutandwa @jlettvin @paberline @komeilr @NemoDomum @justinjk007 @SwapnilBorse123 @MostertMB @siebeniris @amendment19 @RianWardana The ppa:ubuntu-toolchain-r/test has old compiler builds that don't correctly compile some dkms kernel drivers, like nVidia, and you can get your installation pretty broken with the compilers from this PPA. See this launchpad issue for details. |
This comment has been minimized.
This comment has been minimized.
|
That article is really informative! Thanks. |
This comment has been minimized.
This comment has been minimized.
|
This might not be the right place to ask for it, but is there a possibility to install llvm + clang 5 toolchain for ubuntu 14.04 for armhf? I found ppa which has x86 and amd64, also 16.04 and newer have it in their repos? gcc is a bit buggy on arm, and also very demanding with memory consumption -_- where clang is just a blast. Faster in compiling, memory cut down by 50 to 80% (tested with amd64 and firefox), and also faster binaries. Will llvm-4 and llvm-5 be added to trusty, as firefox seems to now depend on at least llvm-4? |
This comment has been minimized.
This comment has been minimized.
|
It works, for me when I've tried to install strongswan from source code! |
This comment has been minimized.
This comment has been minimized.
|
It works, thank you :) |
This comment has been minimized.
This comment has been minimized.
|
Thanks, it works! |
This comment has been minimized.
This comment has been minimized.
|
Works like a charm! |
This comment has been minimized.
This comment has been minimized.
|
works perfectly! |
This comment has been minimized.
This comment has been minimized.
|
GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:
select gcc-9 |
This comment has been minimized.
This comment has been minimized.
|
ivanmara555 thanks that works great on my Ubuntu 16 install! |
This comment has been minimized.
This comment has been minimized.
|
THANK YOU! I have been searching for a solution nearly 10 hours, and finally your method works for me! |
This comment has been minimized.
This comment has been minimized.
|
method above now install gcc 8.1.0 ... Congratulations!) |
This comment has been minimized.
This comment has been minimized.
|
@ivanmara555 , I used above command, but only gcc 8.0.1 is installed (not 8.1.0).
My platform is |
This comment has been minimized.
This comment has been minimized.
|
@F001 I got into the same situation on Ubuntu 14.04.5 LTS. |
This comment has been minimized.
This comment has been minimized.
|
Many thanks.. it works greats :) |
This comment has been minimized.
This comment has been minimized.
|
Worked, Thank you very much |
This comment has been minimized.
This comment has been minimized.
|
thanks |
This comment has been minimized.
This comment has been minimized.
|
Nicely done and much appreciated. Thank you @ivanmara555 et al. |
This comment has been minimized.
This comment has been minimized.
|
Love you sir, it worked ! |
This comment has been minimized.
This comment has been minimized.
|
sudo apt-get install python-software-properties needed for Ubuntu 12.04 in order to run add-apt-repository |
This comment has been minimized.
This comment has been minimized.
|
Thank you! |
This comment has been minimized.
This comment has been minimized.
|
http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/dists/jessie/main/binary-amd64/Packages 404 Not Found The whole jessie folder is gone. All other distros are there. |
This comment has been minimized.
This comment has been minimized.
|
Great !! saved a lot of time. |
This comment has been minimized.
This comment has been minimized.
|
Here is the Docker friendly format
also available on https://hub.docker.com/r/88plug/gcc-8-ubuntu-18.04/ |
This comment has been minimized.
This comment has been minimized.
|
Thank you! |
This comment has been minimized.
This comment has been minimized.
|
thanks a lot :) |
This comment has been minimized.
This comment has been minimized.
|
hi... |
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Thank you @peterhanneman. |
This comment has been minimized.
This comment has been minimized.
|
Thank you very much @ivanmara555 sudo apt-get update -y &&
sudo apt-get install build-essential software-properties-common -y &&
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y &&
sudo apt-get update -y &&
sudo apt-get install gcc-8 g++-8 -y &&
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-8 &&
sudo update-alternatives --config gcc
select gcc-8And the final version of gcc is 8.1.0. @F001 |
This comment has been minimized.
This comment has been minimized.
|
Thanks. It works perfectly! |
This comment has been minimized.
This comment has been minimized.
|
Thank you a lot but I'm getting confused if the g++ was well install, because I got error during the installation update-alternatives: error: no alternatives for g++ Then when I did g++ -v, I got: |
This comment has been minimized.
This comment has been minimized.
|
thanks @peterhanneman |
This comment has been minimized.
This comment has been minimized.
|
Not working on UBUNTU 12.04, below the errors sameh@sameh-HP-EliteBook-2570p:~$ sudo apt-get update && \
|
This comment has been minimized.
This comment has been minimized.
|
Worked like a charm for me. Thanks a ton. |
This comment has been minimized.
This comment has been minimized.
|
GCC 9.1.0 on Ubuntu 14.04 & 16.04 & 18.04:
select gcc-9 |
This comment has been minimized.
This comment has been minimized.
|
Thank you!! |
This comment has been minimized.
This comment has been minimized.
|
Thanks @peterhanneman
|
This comment has been minimized.
This comment has been minimized.
|
Just in case if someone wants to make multilib ( gcc/g++ -m32 ) work then they also need to install gcc multilib packages
in my case |
This comment has been minimized.
This comment has been minimized.
Thank you very much worked for me as well on 16.04 |
This comment has been minimized.
This comment has been minimized.
|
GCC 9.2.1 on Ubuntu 14.04 & 16.04 & 18.04:
select gcc-9 |
This comment has been minimized.
This comment has been minimized.
|
@ivanmara555 |
This comment has been minimized.
This comment has been minimized.
|
for gcc-3.4 or any older versions of gcc? |
This comment has been minimized.
This comment has been minimized.
|
@ivanmara555 |
This comment has been minimized.
This comment has been minimized.
|
Thanks a lot ! It worked like charm in difficult setup. |
This comment has been minimized.
This comment has been minimized.
|
@ivanmara555 Thankss, it's work on 16.04 |
This comment has been minimized.
This comment has been minimized.
|
Thanks a lot ! for gcc-4.9? |
This comment has been minimized.
This comment has been minimized.
|
GCC 10.1.0 on Ubuntu 16.04 & 18.04 & 20.04:
select gcc-10 |
This comment has been minimized.
This comment has been minimized.
To ivanmara555's comment using the ppa repository... As of today May 25th 2020 on Ubuntu 20.04 your list of commands does not install the latest 10.1.0. Instead, it installs the older "10.0.1 20200416 (experimental) (Ubuntu 10-20200416-0ubuntu1)" -- because the older version is the only one there at that PPA site for release "Focal". The other package "10.1.0-2ubuntu1~18.04" is for "Bionic" not "Focal". On 20.04, run the following commands today (May 25th, 2020) and it shows that none of the packages are 10.1:
If you can't find a PPA with "10.1.0", you'll have to build it from source. As a side note, the daily build of the next Ubuntu 20.10 does install 10.1.0. Today's screenshot of repo https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test/+packages: |
This comment has been minimized.
This comment has been minimized.
|
Thx |
This comment has been minimized.
This comment has been minimized.
Doesn't seem to work for GCC 10 on 16.04:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thank you very much! |
This comment has been minimized.
This comment has been minimized.
|
I extended the steps above, as they complain with #!/bin/bash
GCC_GXX_VERSION=9
gcc_alternatives=(gcc cc)
gxx_alternatives=(g++ c++ cpp)
all_alternatives=("${gcc_alternatives[@]}" "${gxx_alternatives[@]}")
remove_alternatives() {
alternatives=("$@")
for alt in "${alternatives[@]}"; do
sudo update-alternatives --remove-all $alt || continue
done
}
install_and_set_alternatives() {
path=$1
shift
alternatives=("$@")
for alt in "${alternatives[@]}"; do
sudo update-alternatives --install /usr/bin/$alt $alt $path 100
sudo update-alternatives --set $alt $path
done
}
print_green() {
args=$@
echo -e "\033[0;32m$args\033[0m"
}
check_versions() {
alternatives=("$@")
for alt in "${alternatives[@]}"; do
print_green "$alt\t->\t`$alt --version | head -n 1`"
done
}
install_gcc_gxx() {
sudo apt-get update -y &&
sudo apt-get upgrade -y &&
sudo apt-get dist-upgrade -y &&
sudo apt-get install build-essential software-properties-common -y &&
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y &&
sudo apt-get update -y &&
sudo apt-get install gcc-$GCC_GXX_VERSION g++-$GCC_GXX_VERSION -y
}
install_gcc_gxx
remove_alternatives "${all_alternatives[@]}"
install_and_set_alternatives "/usr/bin/gcc-$GCC_GXX_VERSION" "${gcc_alternatives[@]}"
install_and_set_alternatives "/usr/bin/g++-$GCC_GXX_VERSION" "${gxx_alternatives[@]}"
echo
echo "Check the following versions:"
check_versions "${all_alternatives[@]}" |



This comment has been minimized.
Worked without any issues on a new install of Ubuntu 16.04. Thank you..