Remove documentation to save hard drive space

40,483

Solution 1

According to the Ubuntu wiki, you can instruct dpkg not to install any documentation. This should prevent any documentation (except copyright info) from being installed by apt.

Create a file /etc/dpkg/dpkg.cfg.d/01_nodoc which specifies the desired filters. Example:

path-exclude /usr/share/doc/*
# we need to keep copyright files for legal reasons
path-include /usr/share/doc/*/copyright
# if you also want to remove the man pages uncomment the next line
#path-exclude /usr/share/man/*
path-exclude /usr/share/groff/*
path-exclude /usr/share/info/*
# lintian stuff is small, but really unnecessary
path-exclude /usr/share/lintian/*
path-exclude /usr/share/linda/*

Then you can manually remove any documentation already installed:

find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true
find /usr/share/doc -empty|xargs rmdir || true
rm -rf /usr/share/groff/* /usr/share/info/*
rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

If you also want to remove the man pages do:

rm -rf /usr/share/man/*

The example is written for OEMs, but it worked just as well for me. Took my /usr/share/doc/ directory down from ~150MB to ~20MB.

Solution 2

This should remove the documentation for latex-related packages:

sudo apt-get --purge remove tex.\*-doc$

It does save a few hundred MB.

Solution 3

Quick-and-dirty way to find the installed texlive packages (I'm 100% sure there are other ways):

dpkg -l | grep '^ii.*texlive.*doc'

And removing them:

apt-get remove --purge \
  texlive-fonts-recommended-doc texlive-latex-base-doc texlive-latex-extra-doc \
  texlive-latex-recommended-doc texlive-pictures-doc texlive-pstricks-doc

Solution 4

Do you know what is taking up all of that space? My /usr/share/doc is only ~50MB. If not, use the Disk Analyzer application or go to the terminal and run cd /usr/share/doc; then run du -h -d 1 to find out what is using all of that space. Once you know which program or program are the problem then you can decide if you should remove the directories in /usr/share/doc or not.

Solution 5

A small modification to mopagemo's answer. If LaTeX was originally installed via texlive-full, then removing that metapackage will lead to all of its dependencies being added to the autoremove queue. To fix this, we need to flag the packages as manually installed.

Here's a list of the steps I took to remove the docs and remove the desired packages from the autoremove queue:

  1. sudo apt-get --purge remove tex.\*-doc$
  2. Copy the packages that appear between "The following packages were automatically installed and are no longer required" and "Use 'sudo apt autoremove' to remove them." into a text editor, and remove all the new lines.
  3. Try to sudo apt-get install all of these packages.
  4. You will probably get a series of "Unable to locate package" messages. Remove these ghost packages from the list in your text editor.
  5. Try sudo apt-get install again on the smaller list. This should flag all of the packages as manually installed.
  6. You may get another "no longer required" message. If so, repeat steps 2--5.

It doesn't take long to do this, and the benefit is that you aren't breaking any existing packages or dependencies. You could even reinstall texlive-full over the top. You might want to keep a list of the flagged packages if you intend to uninstall completely at some point.

This freed up just over 1000 MB on my system.

Share:
40,483

Related videos on Youtube

Martin Scharrer
Author by

Martin Scharrer

I'm a electronic engineer which likes to program.

Updated on September 18, 2022

Comments

  • Martin Scharrer
    Martin Scharrer almost 2 years

    I like to create a rather small Ubuntu installation in a Virtual Box machine. It should basically just provide TeX Live and related tools. I figured now that I have almost 1GB of data under /usr/share/doc. I don't need this documentation in this case, just the LaTeX related man pages, which are not located there.

    Is there a way to uninstall all these documentation files using apt-get?
    Alternatively, is it reasonably save to just delete the content of /usr/share/doc?
    I like to share the Virtual Box machine with others, which shouldn't run in trouble.

  • Martin Scharrer
    Martin Scharrer about 12 years
    I was not aware that the directory names under /usr/share/doc are the packages names. At least of some this seems to be true. I used du -sc * | sort -n in /usr/share/doc. Most space was taken from the TeX Live 2009 documentation files which I don't want anyway, because I have the manually installed TL 2011 ones. Thanks, while I still like to see if there is a way to tell apt-get to get ride of most documentation, this solution worked out fine for this case.
  • joar
    joar almost 11 years
    This seems to remove my texlive-full package too.
  • A T
    A T over 9 years
    I had to recreate one of those folders to get @denilson-sá purge recommendation to work. Specifically: mkdir /usr/share/info.
  • rubo77
    rubo77 over 9 years
    On a local machine, you could also delete the copyright files, which will save another ~50MB. Comment this line like: # path-include /usr/share/doc/*/copyright
  • ahcox
    ahcox over 9 years
    The first line (plus deleting copyright) left me with 37MB on 13.04. There are lots of symlinked files that are missed by the find. This helps by 5MB: find /usr/share/doc | egrep "\.gz" | xargs rm. This drops the size down to 26 MB: find /usr/share/doc | egrep "\.pdf$" | xargs rm. Down to 21 MB: find /usr/share/doc | egrep "\.tex$" | xargs rm. There are loads more files left behind though.
  • Andrew Ensley
    Andrew Ensley almost 8 years
    @AT, the commands in my answer don't remove /usr/share/info; just its contents. The directory should still be there after running them.
  • Balazs
    Balazs almost 8 years
    And for those who aren't comfortable with du: you can use Baobab to analyze disk usage. Though one does need to run it as root (sudo baobab) to index the contents of /
  • Jus12
    Jus12 over 7 years
    This also removes texlive-full on Ubuntu 16.04.
  • Jus12
    Jus12 over 7 years
    I don't recommend this step for a few MBs. I did and my system got broken. For instance, Virtualbox checks for installation by checking if a directory /usr/share/doc/virtualbox exists..Created the directory and all worked well. Took me around 2 days to figure that out. Talk about space-time trade-off!
  • Andrew Ensley
    Andrew Ensley over 7 years
    @Jus12 Good point. I certainly wouldn't recommend this as a rule, but if you're desperate for space (like I was with a 16GB Chromebook when I found this), it's worth the trade-off. I certainly didn't have room for virtual machines (or a lot of other software) anyway.
  • Denilson Sá Maia
    Denilson Sá Maia over 7 years
    texlive-full is a metapackage that pulls all the dependencies, including the documentation.
  • Jus12
    Jus12 over 7 years
    Ironically, I wanted to free space to make up room for some virtual disks.
  • nealmcb
    nealmcb over 7 years
    @joar That's intended. texlive-full is a metapackage that pulls all the dependencies, including the documentation
  • isarandi
    isarandi almost 5 years
    @nealmcb, But then autoremove will remove all your tex packages. In more detail: if you had installed tex through texlive-full, and then remove the doc packages, then texlive-full will be gone. Then next time you run apt-get autoremove, all your tex packages will be gone as well, because the only reason they were there is because they depended on texlive-full, which is not there any more.
  • nealmcb
    nealmcb almost 5 years
    @isarandi If you used texlive-full for installation, that sounds like a good point. Some more refs: 2017 proposal to split out the docs: bugs.debian.org/cgi-bin/bugreport.cgi?bug=877862 and more data on sizes: reddit.com/r/LaTeX/comments/2naxke/why_is_texlive_so_large
  • shivams
    shivams almost 5 years
    This is the best and the most no-fuss answer.
  • Lissanro Rayen
    Lissanro Rayen almost 5 years
    I get some errors when running suggested command because some documentation files contained spaces. So I added "-print0" to both "find" commands and "-0" to xargs. After this everything worked as expected.
  • Hielke Walinga
    Hielke Walinga about 4 years
    If you want to keep man to work you have to keep the groff and the man stuff. The current instructions as they are now will make man unable to use afterwards.