15

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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
user1423561
  • 327
  • 1
  • 3
  • 18
  • I'm slightly unclear on what you want to do. Do you need the latest version of GCC, but the one that you built didn't work? Or do you prefer to use the package manager? Or is the version you built from source an older version? – roelofs Aug 14 '14 at 08:58
  • You should have passed something like `--program-suffix=-4.9-mine` at `...../gcc-4.9.1/configure` time – Basile Starynkevitch Aug 14 '14 at 09:00
  • @BasileStarynkevitch is right - you *should* be able to remove that directory from `/usr/local/bin`, and then use the package manager to install a different version. – roelofs Aug 14 '14 at 09:01
  • It is actually a *good idea* to compile *recent* [GCC](http://gcc.gnu.org/) from source code, but you should `...../configure` carefully, and give some `--program-suffix` – Basile Starynkevitch Aug 14 '14 at 09:04
  • @roelofs, it's unlikely there will be a directory under `/usr/local/bin` unless you did something very weird with `--prefix` – Jonathan Wakely Aug 14 '14 at 09:46
  • @JonathanWakely - I've done production installs before, where you make your own directory, and set the prefix to that. Can't remember the exact details, but it worked very well at the time. – roelofs Aug 14 '14 at 13:48
  • @roelofs, and you put it under `/usr/local/bin`?! Like I said, that would be very weird. Maybe you mean `/usr/local` – Jonathan Wakely Aug 14 '14 at 13:53
  • @JonathanWakely - true, probably. This was about 2 or 3 years ago, and I don't have access to that environment anymore. Will also edit my answer below to reflect that. Thanks! – roelofs Aug 14 '14 at 13:57
  • A preferable approach may to use a new release -- Ubuntu 14.04 is also a LTS -- and then [use the PPA prepared by the gcc maintainer](https://wiki.ubuntu.com/ToolChain#PPA_packages) to update to gcc snapshots. – Dirk Eddelbuettel Aug 14 '14 at 14:04
  • http://superuser.com/questions/663788/uninstall-gcc-from-source || http://askubuntu.com/questions/101471/how-to-uninstall-gcc-4-6-2 – Ciro Santilli OurBigBook.com Jun 10 '15 at 12:49

7 Answers7

15

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 :)

Vality
  • 6,577
  • 3
  • 27
  • 48
7

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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 1
    This 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` – Simon Sobisch Oct 13 '17 at 18:06
6

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)
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
1

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.

perror
  • 7,071
  • 16
  • 58
  • 85
Alfaha
  • 11
  • 1
1
/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
0

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.

-1

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.

roelofs
  • 2,132
  • 20
  • 25