69

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.

6 Answers6

50

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.

36

This should remove the documentation for latex-related packages:

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

It does save a few hundred MB.

Eliah Kagan
  • 119,640
mopagemo
  • 377
16

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
3

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.

BobM
  • 31
3

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.

Eliah Kagan
  • 119,640
notkevin
  • 731
0

is it reasonably sa[f]e to just delete the content of /usr/share/doc?

If you do that, the files will get reinstalled when any of the packages get upgraded. You should instead remove the relevant documentation packages, which often (but not always) end in -doc.