There is one thing (thank you @kos):
I definitely wouldn't remove
gccin general, but if I had to I wouldn't do it this way: this will remove alsobuild-essentialand hencemake; for one, if you have the nVidia > drivers installed it will remove those as well, since they depend onmake, plus who knows what other stuff.
With other words, know what you do. ;-)
If you only need a reinstall, use
sudo apt-get install --reinstall gcc-4.9
If you really, really need to remove gcc-4.9, use this short and dangerous command:
sudo apt-get purge gcc-4.9
Answer from A.B. on askubuntu.comThere is one thing (thank you @kos):
I definitely wouldn't remove
gccin general, but if I had to I wouldn't do it this way: this will remove alsobuild-essentialand hencemake; for one, if you have the nVidia > drivers installed it will remove those as well, since they depend onmake, plus who knows what other stuff.
With other words, know what you do. ;-)
If you only need a reinstall, use
sudo apt-get install --reinstall gcc-4.9
If you really, really need to remove gcc-4.9, use this short and dangerous command:
sudo apt-get purge gcc-4.9
use below command , --purge remove option is equivalent to purge
sudo apt-get --purge remove gcc-4.9
according apt-get manual:
--purge
Use purge instead of remove for anything that would be removed. An
asterisk ("*") will be displayed next to packages which are
scheduled to be purged. remove --purge is equivalent to the purge
command. Configuration Item: APT::Get::Purge.
Videos
When you build a package from source there is unfortunately no magic uninstall usually, however you can approximate this, credit to this mailing list thread.
Basically you should install again into a temporary directory and list all the files created in said directory, then you can delete all of them from the main system through a script.
Here is an example of a script to uninstall GCC in this way:
make install DESTDIR=/tmp/gccinst
find /tmp/gccinst | sed -e s,/tmp/gccinst,, | \
(while read F; do rm "$F"; done)
Run it from inside the gcc source directory as root.
To answer your second question you can install the latest gcc available in the ubuntu repo with:
apt-get install gcc
Overlay repos may have newer versions, I have seen a suggestion there is a newer version at ubuntu-toolchain-r/test (install via):
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
But I am not sure if they have added 4.9 there yet. If not you will indeed have to install from source.
EDIT:
It looks like @roelofs found a better guide to install the repo in his answer, so go look there too and remember to give him an upvote if it helps :)
In GCC 5.1.0, although there is no top-level uninstall target, some directories do have it, in particular gcc, so you can do:
cd build/gcc
sudo make uninstall
This does not remove everything that was installed, but it removes major executables like gcc, g++, cpp... contained in that directory, so it might be enough.
Using aptitude instead of apt-get I was able to downgrade existing packages and then install as normal.
Googling your error reveals the answer over on Ask Ubuntu -- it seems you've "held" a package (I'd wager GCC) at an earlier version, and that's causing apt-get to fail to resolve dependencies that require a more recent version.
To un-hold the package, follow the link in the comments on that answer, which will take you to another question also answered over there.
Indeed, there is no "uninstall" command when installing from source, unless the developer has decided to put one in. (i.e., it's not impossible for a developer to create a script that undoes everything)
Your only option is to go into /usr/local/bin/ and remove each file yourself. But which ones to remove?
One solution is to reinstall 5.4, but specify a new directory that isn't /usr/local/bin/. This will give you a list of files that 5.4 installed. Then, using the list of files, go into /usr/local/bin/ and remove them manually. Note that it probably installed libraries and documentation into other directories, so to remove it completely, you will have to do more than just /usr/local/bin/.
An alternative is to not do an uninstallation and just install gcc 4-8 on top of 5.4. It's the same program, but just a different version. So gcc version 4.8 will overwrite 5.4. The "downside" is that you might have 5.4 files lying around, but they will just occupy (relatively little) space. It'll solve your problem and you can move ahead with what you want to do.
Of the two options, I'd pick the second one. The 5.4 files that remain won't affect your system. Relative to images, video, or almost any type of data, the space they occupy is fairly little (i.e., compiler, libraries, documentation is probably small). In the future, you should install it in another directory and add symbolic links manually. update-alternatives would do that for you if it's a package installed compiler; but for a compiler installed from source, that isn't an option.
(Aside: Ubuntu 14.04 has reached end of life, I think. You might consider upgrading some day... If so, then what /usr/local/bin/ looks like won't matter anymore!)
Just create a symbolic link to gcc-4.8
cd /usr/bin
sudo rm gcc
sudo ln -s gcc-4.8 gcc
now try
gcc --version
And see if you got the desired result