APT is a collection of tools for managing the installation of software packages on Debian based Linux distributions, including Ubuntu and Raspbian.
The following instructions show you how to only install the required packages, free up disk space by removing support for unused locales, and (if necessary) connect using a proxy server.
Skip optional packages
By configuring APT not to download the details of any source packages and not to install any recommended or suggested packages, you can minimize the amount of disk space required by the system. You may occasionally find that some functionality you were expecting is ‘missing’ but this is usually solved by tracking down the additional optional package or packages required, and installing them separately.
As a beginner when I decided not to install everything automatically there were times when this did cause some minor issues, but as a result I do now know a bit more about how Linux works and what does what than I would have done otherwise. These days it is much less troublesome, probably because package maintainers are doing a better job of identifying all the required packages that their software depends on.
To modify the configuration you need to be running as a superuser.
$ su Password:
$ sudo -i Password:
First we will remove the entries in that tell APT where to download the source packages. These are packages that just contain the source code to allow you to recompile applications your self and are not something you will normally require.
# vi /etc/apt/sources.list
Comment out any lines beginning with ‘deb-src’ as shown below.
deb http://ftp.uk.debian.org/debian/ wheezy main contrib # deb-src http://ftp.uk.debian.org/debian/ wheezy main deb http://security.debian.org/ wheezy/updates main contrib # deb-src http://security.debian.org/ wheezy/updates main deb http://ftp.uk.debian.org/debian/ wheezy-updates main contrib # deb-src http://ftp.uk.debian.org/debian/ wheezy-updates main
Next we will tell apt only to install the additional packages that are required and not to download or install any recommended or suggested packages. For recent Debian or Raspbian distributions (squeeze wheezy jessie) use the following command to create a new file.
# vi /etc/apt/apt.conf.d/10norecommends
Then insert the following two lines to prevent recommended or suggested packages being automatically installed.
APT::Install-Recommends "0"; APT::Install-Suggests "0";
For older Debian distributions (lenny) use the following command to create a new file, then insert the same text as above.
# vi /etc/apt/apt.conf
Removing unwanted locales
To reduce the amount of system resources used by each software package we can delete the language specific files associated with the locales we are not using. To do this we need to install a utility called localepurge.
# apt-get install localepurge Reading package lists... Done Building dependency tree : : : Creating config file /etc/locale.nopurge with new version #
During the installation you will be prompted to select the locales you wish to keep on your system. When you run localpurge for the first time it will delete any unwanted locale specific files that are already present, and will be run automatically whenever you install any additional packages so you should not need to run it ‘manually’ again.
# localepurge localepurge: Disk space freed in /usr/share/locale: 46820 KiB localepurge: Disk space freed in /usr/share/man: 3604 KiB Total disk space freed by localepurge: 50424 KiB #
Using a web proxy
If you are behind a proxy server you can either export the proxy settings as environment variables (see below) or include the proxy settings a configuration file. For recent Debian or Raspbian distributions (squeeze wheezy jessie) use the following command to create a new file.
# vi /etc/apt/apt.conf.d/01Proxy
For older Debian distributions (lenny) use the following command to edit the configuration file instead.
# vi /etc/apt/apt.conf
Then insert the appropriate proxy settings.
Acquire::http::proxy "http://proxy:port"; Acquire::ftp::proxy "ftp://proxy:port"; Acquire::https::proxy "https://proxy:port";
If your proxy server requires authentication then you will need to include your (proxy) username and password. There are obvious disadvantages to this approach, but once it is configured you won’t need to remember to do anything else.
Acquire::http::proxy "http://username:password@proxy:port"; Acquire::ftp::proxy "ftp://username:password@proxy:port"; Acquire::https::proxy "https://username:password@proxy:port";
If you don’t want to save your username and password in a configuration file you can export the required proxy settings to an environment variable instead.
# export http_proxy=http://username:password@proxy:port # export ftp_proxy=ftp://username:password@proxy:port # export https_proxy=https://username:password@proxy:port # apt-get install package-name
You may find the environment variables are already defined as some web browsers will create them for you automatically.