简体   繁体   中英

How to uninstall gcc installed from source?

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?

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.

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)

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.

the following operation isreally ok. when you make one gcc from source code and make install at gcc-build,then it will generaton one gcc direction at source code's top direction. cd $source_code_top/gcc , then make uninstall. it will purge remove gcc from you linux system.

/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

The highest available version of GCC in the 12.04 repositories is 4.6. You can use the package manager to install a newer version, but you will have to add a PPA. This link should help, although it is for a slightly older version of GCC (but can be used for the newest version).

As a commenter pointed out, if your own built version of GCC was compiled with the --prefix parameter, the entire installation should be in that directory under /usr/local or wherever you installed it, and can be removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM