Tuesday, April 30, 2024
229
rated 0 times [  229] [ 0]  / answers: 1 / hits: 391394  / 1 Year ago, wed, may 24, 2023, 10:15:50

I want to compile my program with the latest version of gcc.



Ubuntu 14.04 comes with gcc 4.8.2, however there's 4.9.0 available, moreover, I see that it is available as a package: gcc-4.9. I tried to install it



sudo apt-get install gcc-4.9


but it says



Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'gcc-4.9-base' for regex 'gcc-4.9'
gcc-4.9-base is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.


Looks like it is already installed, just not as the default one? How do I utilize it to build my program?


More From » software-installation

 Answers
7

The best way to correctly install gcc-4.9 and set it as your default gcc version use:


sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

The --slave, with g++, will cause g++ to be switched along with gcc, to the same version. But, at this point gcc-4.9 will be your only version configured in update-alternatives, so add 4.8 to update-alternatives, so there actually is an alternative, by using:


sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

Then you can check which one that is set, and change back and forth using:


sudo update-alternatives --config gcc

If you have an issue with update-alternatives gcc priority 60 not being higher than previous versions installed you can use the previous update-alternatives --config gcc command to check installed versions and use:


sudo update-alternatives --remove gcc

Or:


sudo update-alternatives --remove-all gcc

NOTE: You could skip installing the PPA Repository and just use /usr/bin/gcc-4.9-base but I prefer using the fresh updated toolchains.




For GCC 5.X or 6, the packages (and correspondingly, the commands) are just called gcc-5, gcc-6, etc. This is due to the change in GCC's version scheme, where 5.1 is the first GCC 5 release, and future 5.X releases are for bug fixes.


[#25188] Thursday, May 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tiowift

Total Points: 119
Total Questions: 113
Total Answers: 110

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
;