How to uninstall gcc installed from source?
Asked Answered
M

8

16

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?

Manmade answered 14/8, 2014 at 8:52 Comment(10)
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?Outflow
You should have passed something like --program-suffix=-4.9-mine at ...../gcc-4.9.1/configure timeProximal
@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.Outflow
It is actually a good idea to compile recent GCC from source code, but you should ...../configure carefully, and give some --program-suffixProximal
@roelofs, it's unlikely there will be a directory under /usr/local/bin unless you did something very weird with --prefixParmenides
@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.Outflow
@roelofs, and you put it under /usr/local/bin?! Like I said, that would be very weird. Maybe you mean /usr/localParmenides
@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!Outflow
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 to update to gcc snapshots.Haymaker
superuser.com/questions/663788/uninstall-gcc-from-source || askubuntu.com/questions/101471/how-to-uninstall-gcc-4-6-2Pickaninny
D
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 :)

Dominate answered 14/8, 2014 at 8:57 Comment(2)
On 12.04, apt-get will install 4.6, not 4.9.Outflow
@Outflow Oh, I see. I just noticed your link has a better guide for installing the repo.Dominate
P
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.

Pickaninny answered 10/6, 2015 at 15:12 Comment(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 && popdNumbskull
C
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)
Chastity answered 25/2, 2015 at 17:17 Comment(1)
do rm "$F"did not work on CentOS install for some reason... had to do do unlink "$F" to make this run without errorFresh
S
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.

Sakmar answered 14/1, 2016 at 19:58 Comment(0)
K
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
Krummhorn answered 15/3, 2019 at 5:39 Comment(0)
K
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.

Krummhorn answered 15/3, 2019 at 5:35 Comment(0)
E
0

For ubuntu 22.04 at least, if you have been building GCC from source and configuring without a specific install path using a prefix, running stock $ sudo make install then it would have installed in /usr/local/bin.

For example, these are my configure and build commands for GCC-13.2...

$ mkdir ./build && cd ./build && \
../configure             \
--program-suffix=-13.2   \
--disable-multilib       \
--enable-default-pie     \
--enable-default-ssp     \
--disable-fixincludes    \
--enable-languages=all   \
&& make -j$(( $(nproc) +2 ))
$ make -k check
$ sudo make install

The above would have used the "build" folder as a workspace then the final command would have installed all the binaries into

/usr/local/...

So to uninstall is easy. Just look for all the stuff that was installed in

/usr/local/

that is suffixed. Of course the assumption is that you would have done a suffix that is distinguishable (mine is "13.2").

Fortunately even if you didn't ubuntu repo GCC binaries are not installed in

/usr/local/

but are installed in

/usr/

with executables in

/usr/bin/

So there is no chance you could have clobbered the repo versions of GCC.

In my case to automate removing GCC versions I built from source and installed to default "/usr/local/..." I run this, in this example it is for GCC-13.1

sudo rm -rv $(locate "13.1" | grep "/usr/local/")

If you want to see what will be removed just remove the rm command and $( ) brackets...

locate "13.1" | grep "/usr/local/"

Now with the above you can safely build and remove GCC as new versions come and go in ubuntu.

Enthusiastic answered 8/5 at 8:35 Comment(0)
O
-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.

Outflow answered 14/8, 2014 at 8:56 Comment(2)
GCC source tree does not have an uninstall target to makeProximal
It's --prefix not --set-prefix and if you use --prefix=DIR then the entire installation will be under DIR, not under /usr/local/binParmenides

© 2022 - 2024 — McMap. All rights reserved.