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?
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 :)
apt-get
will install 4.6, not 4.9. –
Outflow 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.
pushd build && for d in $(ls -d */); do sudo make -C $d uninstall; done && popd
–
Numbskull 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)
do rm "$F"
did not work on CentOS install for some reason... had to do do unlink "$F"
to make this run without error –
Fresh 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.
/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 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.
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.
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.
uninstall
target to make
–
Proximal --prefix
not --set-prefix
and if you use --prefix=DIR
then the entire installation will be under DIR
, not under /usr/local/bin
–
Parmenides © 2022 - 2024 — McMap. All rights reserved.
--program-suffix=-4.9-mine
at...../gcc-4.9.1/configure
time – Proximal/usr/local/bin
, and then use the package manager to install a different version. – Outflow...../configure
carefully, and give some--program-suffix
– Proximal/usr/local/bin
unless you did something very weird with--prefix
– Parmenides/usr/local/bin
?! Like I said, that would be very weird. Maybe you mean/usr/local
– Parmenides