How to uninstall gcc installed from source?
Solution 1
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 :)
Solution 2
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.
Solution 3
Vality has a great start
make install DESTDIR=/tmp/gccinst
But his cleanup command has a few problems. First, it passes directories to rm
, including the usual directories (such as /usr
). We can fix this via -type f
:
find /tmp/gccinst -type f | sed -e s,/tmp/gccinst,, | \
(while read F; do rm "$F"; done)
Getting rid of the directories that this leaves empty...
find /tmp/gccinst -depth -type d -not -empty | sed -e s,/tmp/gccinst,, | \
(while read F; do rmdir -p --ignore-fail-on-non-empty "$F"; done)
Solution 4
add to Vality and Ben. If you do this from your own login shell:
find $HOME/tmp/gccinst/ -type f | sed -e s,$HOME/tmp/gccinst,, | (while read F; do rm **-f** "$F" ; done)
Need -f
flag or the script may not run if there's some permission issue.
Solution 5
/root/ihome3/gcc-4.6.3/gcc-build-4.6.3/gcc
[root@izwz93atpyz gcc]# make uninstall
rm -rf /usr/local/bin/c++
rm -rf /usr/local/bin/g++
rm -rf /usr/local/share/man/man1/g++.1
rm -rf /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.3
rm -rf /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.6.3
rm -rf /usr/local/bin/gcc
rm -f /usr/local/bin/cpp
if [ x != x ]; then \
rm -f /usr/local//cpp; \
else true; fi
rm -rf /usr/local/bin/gcov`enter code here`
rm -rf /usr/local/share/man/man1/gcc.1
rm -rf /usr/local/share/man/man1/cpp.1
rm -f /usr/local/share/info/cpp.info* /usr/local/share/info/gcc.info*
rm -f /usr/local/share/info/cppinternals.info* /usr/local/share/info/gccint.info*
[root@izwz93atpalb56zydy9bpyz gcc]# pwd
/root/ihome3/gcc-4.6.3/gcc-build-4.6.3/gcc
user1423561
Updated on July 09, 2022Comments
-
user1423561 almost 2 years
How can I uninstall a gcc build which I installed from source.I am using gcc 4.9 and I'm on ubuntu 12.04.
Or is there a way to upgrade to latest gcc versions through the ubuntu repository?
-
Basile Starynkevitch almost 10 yearsGCC source tree does not have an
uninstall
target tomake
-
roelofs almost 10 yearsOn 12.04,
apt-get
will install 4.6, not 4.9. -
Vality almost 10 years@roelofs Oh, I see. I just noticed your link has a better guide for installing the repo.
-
Jonathan Wakely almost 10 yearsIt's
--prefix
not--set-prefix
and if you use--prefix=DIR
then the entire installation will be underDIR
, not under/usr/local/bin
-
1111161171159459134 almost 8 years
do rm "$F"
did not work on CentOS install for some reason... had to dodo unlink "$F"
to make this run without error -
Simon Sobisch over 6 yearsThis is the needed hint for the simplest and still quite complete solution:
pushd build && for d in $(ls -d */); do sudo make -C $d uninstall; done && popd