47

When using apt-get install <package_name>, and there are dependencies that need to be downloaded, the terminal outputs names of additional packages and total size, and asks for confirmation before downloading.

But, when dependencies are satisfied and nothing but the named package needs to be downloaded there is no size output and no confirmation.

When using Synaptic, I can see the total size that new packages that will use after installation but no way to see the size that needs to be downloaded, except to go from package to package and use properties to see the compressed size.

I would like to know if there is a way to see the size of a package(s) in terminal and Synaptic prior to downloading and installing it/them?

0

7 Answers 7

34

In the terminal, for a single package:

apt-cache --no-all-versions show $package | grep '^Size: '

for more than a package:

apt-cache --no-all-versions show $packages | 
    awk '$1 == "Package:" { p = $2 }
         $1 == "Size:"    { printf("%10d %s\n", $2, p) }'

I have no idea about Synaptic.

4
  • 6
    what UNIT is this?
    – tatsu
    Mar 4, 2019 at 17:24
  • I guess that Size is bytes and Installed-Size is KiB but I don't know if this is defined anywhere. E.g. Firefox versions: apt-cache show firefox | grep -E "Package:|Version:|Size:" Jun 13, 2019 at 14:10
  • 6
    Intended human CLI is nowadays apt. For example, apt show firefox | grep Size Jun 13, 2019 at 14:16
  • Found the documentaton: The apt-cache show will emit the actual value specified in the file debian/control the documentation of Installed-Size can be found here: debian.org/doc/debian-policy/… Jun 13, 2019 at 14:19
14

The latest and best way to do this is with apt show, which includes units:

apt show firefox | grep Size

Installed-Size: 202 MB
Download-Size: 51.7 MB

apt show can be used to see lots of other useful information about a package before you install it, including version, dependencies, "Breaks", "Replaces", and a description.

11

apt-cache show <package> or aptitude show <package> will show more information about a package, including its size.

For the package size only, you can use:

apt-cache show <package> | grep Installed-Size

or

aptitude show <package> | grep 'Uncompressed Size'

For .deb packages you can use:

dpkg-deb -I <package>.deb | grep Installed-Size
8
  • 4
    Will it show the size of the dependancies too?
    – Tachyons
    Jul 29, 2013 at 16:37
  • 2
    But including size of the dep's can made your answer efficient. just suggestion my friend,:)
    – rɑːdʒɑ
    Jul 29, 2013 at 16:47
  • 1
    @Jai dpkg-deb -I <package>.deb | grep Installed-Size Jul 29, 2013 at 18:07
  • 6
    For me it returns 68...MB? GB? Spoons?
    – puk
    Jul 14, 2018 at 0:44
  • 2
    up. utterly ridiculous that people omit to say what unit of measurement is being returned.
    – tatsu
    Mar 4, 2019 at 17:24
7

This is also right but size is displayed in bytes. And this shows size in better format but if package is of very small size (say < 1MB) then in-spite of echo 'n'it will install package (Because in that case, apt doesn't prompt).

So, You use --no-download with --assume-no as follows:

sudo apt-get --no-download --assume-no install <package_name> | grep 'Need to get'

Here --no-download argues not to download package and --assume-no is for assuming no (n) in case of any prompt.

Example:

$ sudo apt-get --no-download --assume-no install ttf-devanagari-fonts 2>/dev/null | grep 'Need to get'
Need to get 938 kB of archives.
4
  • 1
    This answer is great because it also includes dependencies. To show the 'real' storage which will be used up, grep for 'additional disk space'
    – Panki
    Oct 28, 2018 at 15:19
  • 1
    Thanks, to me this is THE answer, as most packages will have some dependencies. And this way you can simulate installation start, get both download size and disk space used after install for all needed packages, get the list of dependencies, etc. You can ommit or change grep after pipe depending on what you're looking for. In my case, I sometimes want to compare package size and dependencies before picking a tool for the job. Eg, simple email, pick "ssmtp" or "mailutils" (13x disk space). Now I have a nice command to check before installation.
    – LuxZg
    Feb 9, 2021 at 10:37
  • Does not work: your command prints nothing. I use Ubuntu 22.04
    – Nairum
    Jun 27 at 19:49
  • Maybe this has changed recently, but this command will actually install packages sometimes. Try it with e.g. libmpeg2-4. Jul 5 at 23:06
5

You could use the "dry run" mode, which just pretends to download and install packages

$ aptitude install -sy xlockmore
The following NEW packages will be installed:
  xlockmore 
0 packages upgraded, 1 newly installed, 0 to remove and 27 not upgraded.
Need to get 194 kB of archives. After unpacking 373 kB will be used.
Would download/install/remove packages.
2
  • Tried but I don't see the size. The line: Need to get x of archives. After unpacking x will be used. doesn't show.
    – user14590
    Apr 19, 2011 at 19:08
  • 1
    Sorry, this should be aptitude not apt-get (I have a shell alias for that). Updated. This solution has the advantage of showing what you really need to download (doesn't count already installed dependencies). Apr 19, 2011 at 21:20
0

You could try the below command to see the size of archieves that are needed to be downloaded for a particular package.

echo 'n' | sudo apt-get install package | awk '/^Need to get/ {print $4,$5}'

@enzotib answer is good but it show the size of the archives that are needed to be downloaded in some other format not in mb's. But this command will show the size in Mb's.

Example:

$ apt-cache --no-all-versions show chromium-browser | grep '^Size: '
Size: 41493718

$ echo 'n' | sudo apt-get install chromium-browser | awk '/^Need to get/ {print $4,$5}'
44.4 MB
2
  • echo 'n' | sudo apt-get install <package> still stars installing package if it is of very small size
    – Pandya
    Mar 13, 2016 at 4:09
  • Maybe this has changed recently, but this command will actually install packages sometimes. Try it with e.g. libmpeg2-4. Jul 5 at 23:09
0

Trying to get the total installed size including dependencies for a given package on Ubuntu 20.10:

# export package=fonts-deva
# apt-get --dry-run --assume-no --no-install-recommends install "$package" |
  grep Inst | awk '{print $2}' |
  xargs -i apt-cache show --no-all-versions {} | grep "Installed-Size" |
  awk '{s+=$2} END {print s " kB"}'
4447 kB

This goes through a dry-run installation to see which packages would get installed and sums up their Installed-Size.

Why such a complex approach?
There are issues with existing answers:

  • Size of dependencies may not be included
  • Parsing apt-get output for the message After this operation, 4554 kB of additional disk space will be used. won't work for small packages that get installed without the [Y/n] query.
  • Using apt-get --no-download --assume-no install fonts-deva doesn't work for me:
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
1
  • Your command prints nothing.
    – Nairum
    Jun 27 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy