Linux команда удаления пакетов

Package management with APT

IconsPage/apt.png

Package management via apt-get runs hand-in-hand with the /etc/apt/sources.list file. For information on editing or updating your sources list see SourcesList.

Introduction

This page describes how to handle the packages on your system using apt-get and related commands. For example, you can install a new package, remove an installed package, or update all installed packages to the latest versions.

Commands

IconsPage/example.png

  • Example:
sudo apt-get install ubuntu-desktop

Installation commands

IconsPage/note.pngUse the -s flag to simulate an action. For example: «apt-get -s install » will simulate installing the package, showing you what packages will be installed and configured.

auto-apt

IconsPage/example.png

This command runs under the control of auto-apt. If a program tries to access a file known to belong in an uninstalled package, auto-apt will install that package using apt-get. This feature requires apt and sudo to work.

  • Auto-apt keeps databases which need to be kept up-to-date in order for it to be effective. This is achieved by calling the commands auto-apt update, auto-apt updatedb and auto-apt update-local.
  • Usage example
    • You’re compiling a program and, all of a sudden, there’s an error because it needs a file you don’t have. The program auto-apt asks you to install packages if they’re needed, stopping the relevant process and continuing once the package is installed.

    Maintenance commands

    The same as the above, except add the «smart upgrade» checkbox. It tells APT to use «smart» conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.

    IconsPage/note.png«apt-get dist-upgrade» does not upgrade from a previous version of Ubuntu. For more information of upgrading from a previous version of Ubuntu see http://www.ubuntu.com/getubuntu/upgrading .
    du -sh /var/cache/apt/archives

    IconsPage/example.png

    Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there.

    • For example:
    dpkg-reconfigure fontconfig-config
    echo " hold" | dpkg --set-selections
    IconsPage/info.pngThis command may have the unintended side effect of preventing upgrades to packages that depend on updated versions of the pinned package. apt-get dist-upgrade will override this, but will warn you first. If you want to use this command with sudo, you need to use echo " hold" | sudo dpkg --set-selections not sudo echo " hold" | dpkg --set-selections.
    echo " install" | dpkg --set-selections

    Removal commands

    IconsPage/example.png

    This command completely removes a package and the associated configuration files. Configuration files residing in ~ are not usually affected by this command.

    • + operator
      • If you want to remove package1 and install package2 in one step:
      dpkg -l | grep '^rc' | awk '' | xargs dpkg --purge

      Search commands

      This command determines which installed package owns . It shows files from installed packages that match , with the name of the package they came from. Consider this to be a «reverse lookup» utility.

      IconsPage/info.pngIn order to use this command, the package dlocate must be installed on your system.
      dpkg -L package | grep /usr/bin

      IconsPage/example.png

      For more information on apt-get, apt-cache and dpkg consult their manual pages by using the man command. These manuals will provide a wider scope of information in addition to all of the options that you can use with each program.

        Example:

      Typical usage example

      I want to feel the wind in my hair, I want the adrenaline of speed. So let’s install a racing game. But what racing games are available?

      apt-cache search racing game

      It gives me a lot of answers. I see a game named «torcs». Let’s get some more information on this game.

      Hmmm. it seems interesting. But is this game not already installed on my computer? And what is the available version? Which repository is it from (Universe or Main)?

      Ok, so now, let’s install it!

      What is the command I must type in the console to launch this game? In this example, it’s straightforward («torcs»), but that’s not always the case. One way of finding the name of the binary is to look at what files the package has installed in «/usr/bin». For games, the binary will be in «/usr/games». For administrative programs, it’s in «/usr/sbin».

      dpkg -L torcs | grep /usr/games/

      The first part of the command display all files installed by the package «torcs» (try it). With the second part, we ask to only display lines containing «/usr/games/».

      Hmmm, that game is cool. Maybe there are some extra tracks?

      But I’m running out of space. I will delete the apt cache!

      Oh no, my mother asked me to remove all games from this computer. But I want to keep the configuration files so I can simply re-install it later.

      If I want to also remove config files :

      Setting up apt-get to use a http-proxy

      These are three methods of using apt-get with a http-proxy.

      Temporary proxy session

      This is a temporary method that you can manually use each time you want to use apt-get through a http-proxy. This method is useful if you only want to temporarily use a http-proxy.

      Enter this line in the terminal prior to using apt-get (substitute your details for yourproxyaddress and proxyport).

      export http_proxy=http://yourproxyaddress:proxyport

      If you normally use sudo to run apt-get you will need to login as root first for this to work unless you also add some explicit environment settings to /etc/sudoers, e.g.

      Defaults env_keep = "http_proxy https_proxy ftp_proxy"

      APT configuration file method

      This method uses the apt.conf file which is found in your /etc/apt/ directory. This method is useful if you only want apt-get (and not other applications) to use a http-proxy permanently.

      gksudo gedit /etc/apt/apt.conf

      Add this line to your /etc/apt/apt.conf file (substitute your details for yourproxyaddress and proxyport).

      Acquire::http::Proxy "http://yourproxyaddress:proxyport";

      BASH rc method

      This method adds a two lines to your .bashrc file in your $HOME directory. This method is useful if you would like apt-get and other applications for instance wget, to use a http-proxy.

      Add these lines to the bottom of your ~/.bashrc file (substitute your details for yourproxyaddress and proxyport)

      http_proxy=http://yourproxyaddress:proxyport export http_proxy

      Save the file. Close your terminal window and then open another terminal window or source the ~/.bashrc file:

      Test your proxy with sudo apt-get update and whatever networking tool you desire. You can use firestarter or conky to see active connections.

      If you make a mistake and go back to edit the file again, you can close the terminal and reopen it or you can source ~/.bashrc as shown above.

      How to login a proxy user

      If you need to login to the Proxy server this can be achieved in most cases by using the following layout in specifying the proxy address in http-proxy. (substitute your details for username, password, yourproxyaddress and proxyport)

      http_proxy=http://username:password@yourproxyaddress:proxyport

      Useful additional packages

      Troubleshooting

      Источник

      Как полностью удалить пакет с зависимостями в Linux, использующим пакетный менеджер apt.

      При установке программ, при помощи пакетного менеджера apt, у многих часто возникаем вопрос как их удалять. Для этого есть команды:

      sudo apt-get autoremove имя_программы

      Команда удаляет пакет вместе с зависимости, которые для него устанавливались, и больше ему не нужны.

      sudo apt-get remove имя_программы

      Команда удаляет пакет не затрагивая зависимости.

      sudo apt-get purge имя_программы

      Команда удаляет конфигурационные файлы пакета.

      Казалось бы, на этом все, но не тут-то было, apt-get autoremove не всегда удаляет всё что было установлено вместе с пакетом.

      Что бы наверняка удалить все что было установлено вместе с пакетом, можно посмотреть лог apt:

      cat /var/log/apt/history.log | more

      Пример вывода этой команды:

      Start-Date: 2016-08-03 07:46:19 Commandline: apt-get install samba Install: python-tdb:amd64 (1.3.8-2, automatic), python-samba:amd64 (2:4.3.9+dfsg -0ubuntu0.16.04.2, automatic), python-dnspython:amd64 (1.12.0-1, automatic), sam ba:amd64 (2:4.3.9+dfsg-0ubuntu0.16.04.2), samba-dsdb-modules:amd64 (2:4.3.9+dfsg -0ubuntu0.16.04.2, automatic), libaio1:amd64 (0.3.110-2, automatic), tdb-tools:a md64 (1.3.8-2, automatic), attr:amd64 (1:2.4.47-2, automatic), samba-common:amd6 4 (2:4.3.9+dfsg-0ubuntu0.16.04.2, automatic), samba-vfs-modules:amd64 (2:4.3.9+d fsg-0ubuntu0.16.04.2, automatic), samba-common-bin:amd64 (2:4.3.9+dfsg-0ubuntu0. 16.04.2, automatic), python-ldb:amd64 (2:1.1.24-1ubuntu3, automatic) End-Date: 2016-08-03 07:47:23

      Здесь видно что при установке samba, так же были установлены python-tdb, python-samba и т.д. Соответственно для полного удаления установленного пакета можно набрать команду:

      sudo apt-get autoremove --purge python-tdb python-samba python-dnspython samba samba-dsdb-modules libaio1 tdb-tools attr samba-common samba-vfs-modules samba-common-bin python-ldb

      Для того что бы не искать и не выбирать эти программы из лога вручную можно спарсить лог:

      sudo sed -n '/Commandline: apt-get install имя_пакета/,/End-Date:.*/p' /var/log/apt/history.log | sed -n '/Install.*/p' | sed -e s'/Install: //g' | sed -e s'/:amd64 //g' | sed -e s'/(.[^)]*),\//g' | tr '\n' ' '

      Внимание: эти команды парсят весь лог, т.е. если несколько раз устанавливалась/удалялась программа, на экран выведутся все программы которые были установлены при каждой установке, не только при последней.

      Что бы отображались программы только при последней установке нужно в конце строки заменить «tr ‘\n’ ‘ ‘» на «tail -1», т.е. команда должна быть:

      sudo sed -n '/Commandline: apt-get install имя_пакета/,/End-Date:.*/p' /var/log/apt/history.log | sed -n '/Install.*/p' | sed -e s'/Install: //g' | sed -e s'/:amd64 //g' | sed -e s'/(.[^)]*),\//g' | tail -1

      На экран выведутся программы, которые были установлены при установке пакета.

      Что бы их удалить можно ввести:

      sudo sed -n '/Commandline: apt-get install имя_пакета/,/End-Date:.*/p' /var/log/apt/history.log | sed -n '/Install.*/p' | sed -e s'/Install: //g' | sed -e s'/:amd64 //g' | sed -e s'/(.[^)]*),\//g' | tr '\n' ' ' | sudo xargs apt-get autoremove --purge -y

      Все что устанавливалось при установке вашего пакета, будет удалено.

      Источник

      How can you completely remove a package?

      I am trying to do a clean install of the octave3.2 package. To do this, I removed it, then tried to reinstall it. When I reinstalled, an error occurred. It could be a bug in the package, but I want to make sure I have everything removed so that I can do a clean install. Is it enough to do this?

      sudo apt-get --purge remove octave3.2 

      10 Answers 10

      This is a very general answer to the question about the effects of purging packages. For advice specific to your situation, you’ll have to edit your question to include additional information—in particular, the complete and exact text of the error message you are getting.

      Removing packages with sudo apt purge . or sudo apt —purge remove . will remove them and all their global (i.e., systemwide) configuration files. This is usually what people mean when they talk about completely removing a package.

      But that doesn’t mean your system is the same as it was before the package was installed. In particular:

  • Оцените статью
    Adblock
    detector