After creating a .deb: dpkg:warning while removing, directory /usr/local/bin not empty so not removed

9,341

In general, this warning is completely harmless and normal. When dpkg is removing (or trying to remove) a package, it removes all files and directories which were created as part of that package installation. Now, suppose there are some files in a directory that is a candidate for removal in such a scenario, and dpkg doesn't know about these files. This could happen either because they were machine generated, either during or after the install, or because they were created by a user. Then, unless instructed, dpkg will not remove those files. Since, by default, it will not remove a non-empty directory, in such a case, the directory containing these files will not be removed. So, in summary, after the package is removed, you may end up with a basically empty directory (or directories) with a few machine generated files or something. This is not a problem - you can just remove these manually.

Note, the defaults above are all sensible defaults. There are no bugs here.

In your case, you are installing files to /usr/local as part of your Debian binary package, which is a violation of the File Hierarchy Standard, and is wrong. Don't do this. User binaries should go into /usr/bin, for example, libraries should go into /usr/lib, etc. I assume your package creates /usr/local/bin, because dpkg, naturally, does not know about it already. (Since a Debian package containing files/directories in /usr/local is a violation of the FHS and therefore Debian Policy). Therefore it tries to remove that file when it removes the package. Stop installing in /usr/local, and your problem will go away.

Give us a little more context, perhaps? Why are you trying to build your own zsh Debian package rather than using the one your distribution ships, and what distribution are you using anyway?

If you really want to do this, here is a simple tip. Check how your distribution (or even Debian) packages zsh, and just reuse the packaging. It should work fine. There is no reason to try writing your own, unless you are trying to learn how to package, which I assume is not the case here.

Share:
9,341
Patryk
Author by

Patryk

Software Engineer C++/Go/shell/python coder Linux enthusiast Github profiles: https://github.com/pmalek https://github.com/pmalekn

Updated on September 18, 2022

Comments

  • Patryk
    Patryk over 1 year

    I have created a package of zsh 5.0.7 from sources and now I can install it successfully but when I try to remove it I get this:

    $ sudo dpkg -i zsh_5.0.7_amd64.deb
    Selecting previously unselected package zsh.
    (Reading database ... 177638 files and directories currently installed.)
    Preparing to unpack zsh_5.0.7_amd64.deb ...
    Unpacking zsh (5.0.7) ...
    Setting up zsh (5.0.7) ...
    Processing triggers for man-db (2.7.0.2-2) ...
    Reading package lists...
    Building dependency tree...
    $ sudo apt-get purge zsh
    Reading state information...
    The following packages will be REMOVED:
      zsh*
    0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
    After this operation, 6473 kB disk space will be freed.
    Do you want to continue? [Y/n] (Reading database ... 178746 files and directories currently installed.)
    Removing zsh (5.0.7) ...
    dpkg: warning: while removing zsh, directory '/usr/local/bin' not empty so not removed
    dpkg: warning: while removing zsh, directory '/usr/local/lib' not empty so not removed
    dpkg: warning: while removing zsh, directory '/usr/local/share/man/man1' not empty so not removed
    Processing triggers for man-db (2.7.0.2-2) ...
    

    What can I change in packaging (debian/{control,rules} or other files) to make that warning go away ?

    debian/control

    Source: zsh
    Section: unknown
    Priority: optional
    Maintainer: Patryk <[email protected]>
    Build-Depends: debhelper (>= 8.0.0), autotools-dev
    Standards-Version: 3.9.4
    Homepage: http://zsh.sourceforge.net/
    
    Package: zsh
    Architecture: any
    Depends: ${shlibs:Depends}, ${misc:Depends}, libc6
    Description: ZSH shell
     Zsh is a shell designed for interactive use, although it is also a powerful scripting language. Many of the useful features of bash, ksh, and tcsh were incorporated into zsh; many original features were added.
    

    debian/rules

    #!/usr/bin/make -f
    # -*- makefile -*-
    
    # Uncomment this to turn on verbose mode.
    #export DH_VERBOSE=1
    
    %:
            dh $@  --with autotools-dev
    override_dh_auto_configure:
            ./configure
    override_dh_usrlocal:
    

    EDIT

    I have forked zsh sources and added debian directory for packaging:

    https://github.com/pmalek/zsh/tree/5.0.7-deb/debian

    • Patryk
      Patryk over 9 years
      @terdon I've added debian/control and debian/rules files, anything more that might be helpful?
    • terdon
      terdon over 9 years
      Hmm, they don't seem to be relevant, sorry. I don't really know the first thing about .deb packaging but presumably, there is a file that lists the directories & files that should be created by the package. I thought they might be those two files only because you mentioned them. I am guessing that you need to show whichever file defines these directories since, presumably, one of them lists /usr/bin. Try running grep -wR "/user/bin" /path/to/package/build/dir.
    • Patryk
      Patryk over 9 years
      @terdon output: paste.ubuntu.com/8689535
    • terdon
      terdon over 9 years
      Argh, sorry, I meant /usr/local/bin. Could you post grep -wR "/usr/local/bin[/ ]" /path/to/package/build/dir instead?
    • Alen Milakovic
      Alen Milakovic over 9 years
      I notice you have override_dh_usrlocal: but nothing under it. Did you paste the entire rules file?
    • Ludwig Schulze
      Ludwig Schulze over 9 years
      What template you used for your debian/ directory? I can't reproduce it.
    • Patryk
      Patryk over 9 years
      @FaheemMitha Yes that's entire rules file, I have that overriden to be empty.
    • Patryk
      Patryk over 9 years
      @Braiam I have ran dh_make --native -s --copyright gpl -f ../zsh-5.0.7.tar.gz
    • Alen Milakovic
      Alen Milakovic over 9 years
      @Patryk You may be trying to disable the default action of override_dh_usrlocal, but in that case, please provide details of what you are doing, and why.
  • Patryk
    Patryk over 9 years
    Actually I am trying to learn how to package :) I can't find a guide that will tell me where are "files installed with a package" defined.
  • Alen Milakovic
    Alen Milakovic over 9 years
    man dh_install. debian/package.install are the files normally used.
  • Patryk
    Patryk over 9 years
    Regarding the violation of FHS, from Wiki: "Most of the time /usr/local/ is used for installing software/data that are not part of the standard operating system distribution" - so why is this bad to install software in /usr/local/?
  • Alen Milakovic
    Alen Milakovic over 9 years
    @Patryk Good question. By definition, a deb package is part of the operating system distribution. Source that is installed from source, e.g. with the classic autotools mantra ./configure, make, make install typically goes into /usr/local. Deb binary packages never do.
  • Patryk
    Patryk over 9 years
    So what you say is that is should go to /usr/{bin,lib,man,share}? This still does not solve my problem because I don't know how to define the installation dir nor I do I have package.install file created by dh_make (I have tried looking for it in zsh Ubuntu packaging on launchpad but they don't use it either)
  • Alen Milakovic
    Alen Milakovic over 9 years
    @Patryk if you want someone to debug your packaging, then (a) ask a separate question e.g. "why are my files not ending up in /usr/bin etc" (b) include all your Debian packaging. Since SE does not allow attachments, if it is large/complex, you could point to a repos somewhere. Github and Bitbucket are popular.
  • Alen Milakovic
    Alen Milakovic over 9 years
    Note, if the packaging is small enough to include in the question, you should include it. You could include all files inline, separated in some fashion. I tend to use #s or *s.
  • Patryk
    Patryk over 9 years
    I have added sources with packaging (debian directory).
  • Alen Milakovic
    Alen Milakovic over 9 years
    @Patryk Please ask a different question. Don't add stuff here. See where I wrote "if you want someone to debug your packaging, then (a) ask a separate question..."?
  • Evgeny Vereshchagin
    Evgeny Vereshchagin almost 9 years
    @FaheemMitha, well, there is an exception: local certificate authorities should go into /usr/local/share/ca-certificates. See my answer about building a local CA certificate package
  • Alen Milakovic
    Alen Milakovic almost 9 years
    @EvgenyVereshchagin I may be forgetting the original context, but to be clear, files that are part of the Debian packages should never be located in /usr/local. The reason is simple - that is not part of the system per the FHS. However, the package can install files anywhere it wants - but those files cannot be part of the package.