简体   繁体   English

如何卸载从源安装的gcc?

[英]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. 如何卸载我从源码安装的gcc版本。我正在使用gcc 4.9而我正在使用ubuntu 12.04。

Or is there a way to upgrade to latest gcc versions through the ubuntu repository? 或者有没有办法通过ubuntu存储库升级到最新的gcc版本?

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: 以下是以这种方式卸载GCC的脚本示例:

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. 以root用户身份从gcc源目录中运行它。

To answer your second question you can install the latest gcc available in the ubuntu repo with: 要回答第二个问题,您可以在ubuntu repo中安装最新的gcc:

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): 叠加回购可能有更新的版本,我已经看到有一个建议,在ubuntu-toolchain-r / test(安装通过)有一个更新的版本:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

But I am not sure if they have added 4.9 there yet. 但我不确定他们是否还加了4.9。 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 :) 看起来@roelofs在他的回答中找到了一个更好的指南来安装回购,所以去看那里也记得给他一个upvote如果有帮助:)

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: 在GCC 5.1.0中,虽然没有顶级uninstall目标,但有些目录确实有它,特别是gcc ,所以你可以这样做:

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. 这不会删除已安装的所有内容,但会删除该目录中包含的主要可执行文件,如gccg++cpp ...,这样就足够了。

Vality has a great start Vality有一个很好的开始

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 ). 首先,它将目录传递给rm ,包括通常的目录(例如/usr )。 We can fix this via -type f : 我们可以通过-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. 加入Vality和Ben。 If you do this from your own login shell: 如果您从自己的登录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. 如果存在某些权限问题,则需要-f标志或脚本可能无法运行。

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. 当你从源代码制作一个gcc并在gcc-build中进行安装时,它将在源代码的顶部方向上生成一个gcc方向。 cd $source_code_top/gcc , then make uninstall. cd $ source_code_top / gcc,然后进行卸载。 it will purge remove gcc from you linux system. 它将清除你从linux系统中删除gcc。

/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. 12.04存储库中GCC的最高可用版本是4.6。 You can use the package manager to install a newer version, but you will have to add a PPA. 您可以使用包管理器安装较新版本,但您必须添加PPA。 This link should help, although it is for a slightly older version of GCC (but can be used for the newest version). 这个链接应该有所帮助,虽然它适用于较旧版本的GCC(但可以用于最新版本)。

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. 正如评论者指出的那样,如果你自己构建的GCC版本是使用--prefix参数编译的,那么整个安装应该在/usr/local下的目录中或安装它的任何地方,并且可以删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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