Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Every time I install a new Linux kernel, it gets left in the grub_config, making the boot menu longer each time.

I know I can manually search through the installed packages and remove them.

Does Ubuntu provide any easier way to clean them up or keep them from showing in the boot list?

share|improve this question

36 Answers 36

up vote 333 down vote accepted

11.10 and newer versions of Ubuntu

GRUB2 and its display of all kernels

The latest versions of Grub2 installed in Ubuntu automatically display the latest kernel and hides the older kernels that you may have installed.


If you do not see your grub - then remember to press Shift whilst booting.

As you can see, only the latest kernel is displayed.

If you select the option shown (press Enter) then all the old kernels become visible and available to boot from.

GNU GRUB Previous versions

How to permanently delete older kernels

First boot with the latest available kernel.

There are a number of ways to delete old kernels. Personally, I wouldn't touch Computer Janitor since this is acknowledged to break your computer with its suggestions.


An alternative is Synaptic (sudo apt-get install synaptic)

search for linux-image, right-click a kernel and choose complete removal and finally click the Apply button to delete the kernel.

Synaptic Package Manager

Repeat the search but this time for linux-header - you can delete the associated headers for the kernel image chosen previously.

Synaptic though will not attempt to verify what you are trying to remove... you could inadvertently delete your newest kernel - or even delete all of your kernels via this tool leaving you with an unbootable Ubuntu!.

Remember to check which kernel you are using type:

uname -r

The result would be similar to:

Terminal <uname -r>

Remember the result and the number - make sure you don't delete the corresponding image or header.


IMHO, the best GUI tool is Ubuntu-Tweak

It is not available from the standard repositories. To install in 13.10 and older versions you need to use the author's PPA:

sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak

In Ubuntu 14.04+ you have to download .deb file from official website and install it using Software Center or manually.

Computer Janitor

Choose the options shown by the arrows.

Select both the headers and image with the same version number.

It will not allow you to delete the current kernel you are booted with since the current kernel is not displayed.


My recommendation is to keep at least two or preferably three kernels including the latest. The reason for the recommendation is that you will have at least one/two other kernels to boot with, if for what-ever reason the latest kernel you are unable to boot with or introducing a regressed capability such as broken wireless.

share|improve this answer
Removing old "linux-image*" packages using synaptic, worked well with 10.04 too. (I mention it because the title suggests it may only be for 11.10 and up) –  mivk May 17 '12 at 16:35
the -y switch at the end of the apt-get line is necessary, otherwise apt-get just asks for confirmation and since the input is a pipe, it just aborts. So it should end in: | xargs sudo apt-get purge -y –  Josh Aug 26 '13 at 16:30
if you recommend to keep at least two kernels, you could have written your script to do exactly that ;) (I was just looking for a script that does that, but it seems that I’ll have to write it myself) –  törzsmókus Nov 8 '13 at 12:56
Removing about 20 versions of old linux-image and linux-headers freed 4.5GB of space on my machine. –  Andrew Mao Jan 7 '14 at 19:30
This method works well, but deletion of every kernel excessively regenerates grub.cfg, which takes time. Is there any way of disabling this for batch deletion, then regenerating it once? –  spacediver Mar 25 '14 at 23:47

There is a command called purge-old-kernels that is in bikeshed Ubuntu package (available in universe repository) that can be used to purge extra kernels. It will keep 2 latest kernels and the current one by default. The package has a few dependencies, though.

The following Bash script aims to let user purge some kernels that are older than the currently used one. You can set by an option, how many older kernels it keeps. This has the advantage that it will not purge any newer kernels that may exist e.g when system has not been booted after installing some new kernel(s).

Save the script as purge-older-kernels, make it executable by running chmod a+x ./purge-older-kernels in the directory. Then you can see its usage by running ./purge-older-kernels -?. If you want to use the script like a command, copy the script in "/usr/local/bin". Actual removing requires superuser privileges, i.e. use of sudo.

#  Copyright (C) 2015       Jarno Suni (8@iki.fi)
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  GNU General Public License for more details.
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

set -o nounset
set -o errexit

# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [OPTION]...
Purge some kernel related packages that have older version than the 
current kernel. This is especially useful in order to prevent /boot 
partition from getting full. First warn, if some linux-* packages are
only partially or unsuccessfully installed.

    -h, -?, --help  Display this help and exit.
    -k NUM,
    --keep NUM,
    --keep=NUM      Keep NUM kernels that are older than the currently 
                    used one. Default is 1.
    -s, --simulate  Dry-run; don't actually remove packages. You do not
                    have to be superuser with this option.
    -y, --yes       Purge without user confirmation.

Exit Status:
    Exit with 1, if some command line argument is invalid.
    Inherit the exit status of the apt-get purge command issued.

   echo 'ERROR: '"$1" >&2
   exit ${2:-1}


while :; do
    case ${1-} in       
            if ! ${2:+false}; then
              shift 2
               error 'Must specify a non-empty "--keep NUM" argument.'
            n=${1#*=} # Delete everything up to "=" and assign the remainder.
             error 'Must specify a non-empty "--keep NUM" argument.'
        --)              # End of all options.
            echo 'WARNING: Unknown option (ignored): '"$1" >&2
        # Default case: If no more options then break out of the loop.


if [ $# -ne 0 ] ; then

if ! [[ "$n" =~ ^[0-9]+$ ]] ; then
 error "$n is invalid number of older kernels to keep."
# $n is valid number

Pkgs="$(dpkg-query --show --showformat='${Status} ${Package}\n' "linux-*" |
 awk '$2!="ok" || ($3!="installed" && $3!="not-installed") {print $4}')"
if [ "${Pkgs}" ]; then 
 echo -e "WARNING: The following linux packages are not properly\
 installed. You may want to purge or reinstall them:\n"${Pkgs} >&2
 if ! [[ "$simulate" || "$yes" ]]; then
  read -r -p "Continue anyway (y/n)? " response
  response=${response,,}    # tolower
  ! [[ $response =~ ^(yes|y)$ ]] && exit

# Versions of installed kernel packages
Versions="$(dpkg-query --show --showformat='${Status} ${Package}\n' "linux-image-*" |
sed -nr "s/^[^ ]+ ok installed .+image-([[:digit:].]+-[^-]+)-.+/\1/p" |
sort --version-sort --unique)"

#Alternative way, but maybe not as reliable, if kernel is only partially installed
#Versions="$(ls -1U /boot/vmlinuz-* | cut -d- -f2,3 | sort -Vu)"

# current kernel version number (present in the respective kernel 
# package name, too)
current="$(uname -r | cut -f1,2 -d-)"

# keep n versions that are older than the current one (if they exist).
num=$(awk '($0==c){a=NR-1-n; if(a>0){print a}else{print 0} exit}' c=${current} n=$n <<<"${Versions}")
VersionsToPurge="$(head -n ${num} <<<"${Versions}")"

if [ "${VersionsToPurge}" ]; then
    # purge linux packages matching the versions
    apt-get -q ${simulate} ${yes} purge --auto-remove $(
    sed -r -e 's/\./\\./g' -e 's/.*/^linux-.+-&($|-)/' <<<"$VersionsToPurge")   
    echo "0 kernels purged."

If you just want to purge the kernels (and the related packages) that are older than the currently used kernel, you could use this script.

share|improve this answer
@drevicko See here. –  jarno Jun 8 at 8:27
@drevicko, sure, dlocate -lsbin bikeshed –  jarno Jun 9 at 4:57
@drevicko, see also another question –  jarno Jun 9 at 4:59

My one-liner to remove old kernels (this also frees up disk space)

dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

Explanation (remember, | uses the output of the previous command as the input to the next)

  • dpkg --list lists all installed packages
  • grep linux-image looks for the installed linux images
  • awk '{ print $2 }' just outputs the 2nd column (which is the package name)
  • sort -V puts the items in order by version number
  • sed -n '/'`uname -r`'/q;p' prints the lines before the current kernel
  • xargs sudo apt-get -y purge purges the found kernels

Unwinding the sed invocation:

  • -n tells sed to be quiet
  • `uname -r` outputs the current installed kernel release - we include it in backticks so that the output is includes as part of the command (you might also see this as $(uname -r)
  • /something/q says stop when you match 'something' (in this case, something is output of uname -r) - the / surround a regular expression
  • p is print
  • the ; is the command separtor, so /something/q;p says quit when you match something, else print

altogether, sed -n '/'`uname -r`'/q;p' is print the lines until it matches with the current kernel name.

If you're paranoid (like me), you can make the last part xargs echo sudo apt-get -y purge so that the command to purge the old kernels is printed, then you can check that nothing unexpected is included before you run it.

Modified version to remove headers:

dpkg --list | grep 'linux-image' | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs sudo apt-get -y purge
dpkg --list | grep 'linux-headers' | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs sudo apt-get -y purge

Note: the sed invocation is modified. "$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")" extracts only the version (e.g. "3.2.0-44") , without "-generic" or similar from uname -r

All-in-one version to remove images and headers (combines the two versions above):

echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge
share|improve this answer

This is a pure command line solution.

First generate a list of all installed kernel versions except the currently running kernel:

dpkg-query -W -f='${Package}\n' |
  grep -f <(ls -1 /boot/vmlinuz* | cut -d- -f2,3 |
    grep -v $(uname -r | cut -d- -f1,2))

Alternatively generate a list of all installed kernel versions except the last two:

dpkg-query -W -f='${Package}\n' |
  grep -f <(ls -1 /boot/vmlinuz* | cut -d- -f2,3 |
    sort -V | head -n -2)

Examine the list. Make sure the the kernel versions you want to keep are not part of the list. Use the command uname -r to see the version of the currently running kernel.

If you are happy with the results you can use apt-get to remove the packages.

First a dry run (using the first generator as example):

sudo apt-get --dry-run purge $(
  dpkg-query -W -f='${Package}\n' |
    grep -f <(ls -1 /boot/vmlinuz* | cut -d- -f2,3 |
      grep -v $(uname -r | cut -d- -f1,2)))

Then a real run:

sudo apt-get purge $(
  dpkg-query -W -f='${Package}\n' |
    grep -f <(ls -1 /boot/vmlinuz* | cut -d- -f2,3 |
      grep -v $(uname -r | cut -d- -f1,2)))

If you want to automate the process then add the --yes parameter:

sudo apt-get --yes purge $(
share|improve this answer

I have a script for this that does not need very fancy string parsing.

Remove headers and images except the current one to release space

sudo apt-get autoremove --purge 'linux-headers-[0-9].*' linux-headers-$(uname -r)+ linux-headers-$(uname -r | cut -d- -f1,2)+ 'linux-image-[0-9].*' linux-image-$(uname -r)+
share|improve this answer

I find this to be the easiest and quickest way. It keeps the latest kernel as well as two more:

sudo apt-get -y install bikeshed
sudo purge-old-kernels

To change the number of additional kernels that are kept:

sudo purge-old-kernels --keep 3
share|improve this answer

Purely commandline, this will remove all but the current and second most current (via the "-2" in the head command below):

OLD=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- |
    awk '{print "linux-image-" $0 " linux-headers-" $0}' )
if [ -n "$OLD" ]; then
    apt-get -qy remove --purge $OLD
apt-get -qy autoremove --purge
share|improve this answer
one-liner from there: dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge –  Dmitry Verkhoturov Aug 5 '12 at 19:31
@DmitryPaskal As always, don't just copy-paste these without understanding them. On my machine this one-liner also matches linux-libc-dev:amd64 which shouldn't be removed. –  jamesadney Mar 12 '13 at 20:19
@Kees Cook, shouldn't the awk argument only be surrounded by single-quotes? If your intent is to prepend "linux-image-" to the piped lines, this only seems to work if you use awk '{print "linux-image-" $0}'. –  Mark Jun 12 '13 at 17:33

To figure out what kernels and headers are installed use

dpkg -l | grep linux-image

dpkg -l | grep linux-headers

You can then remove them one by one or together, just make sure to keep the most recent.

There are also some handy commands and scripts to automate the removal.


The following claims to remove all unused kernels and headers:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'|grep -E "(image|headers)" | xargs sudo apt-get -y purge

If you don't ever need old kernels, set that command to run as a monthly cron job.

share|improve this answer

This is by far the best answer in my opinion:


Follows the last command on the site above somewhat tweaked:

sudo apt-get purge $(dpkg -l 'linux-*' | awk '/^ii/{print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -E -e -[0-9]+(\.[0-9]+){2}-[^-]+)
share|improve this answer

The accepted answer using sed to remove older kernels permanently has some flaws, if someone has not rebooted the computer after upgrading kernel the command will remove the newer kernel too.

Here is an alternate solution that will consider all situations to remove actual older kernels only:

kernels=( $(grep -Po "^linux-image-[^-]+-[^-]+-generic\b" < <(dpkg --get-selections)) )
cur_rel=$(grep -Po ".*(?=-[a-z]*$)" < <(uname -r))

for kernel in "${kernels[@]}"; do
    ker_rel=$(grep -Po "[0-9].*(?=-[a-z]*)" <<< "$kernel")
    dpkg --compare-versions "$ker_rel" gt "$cur_rel" && echo "Please Restart your computer first" && break
    dpkg --compare-versions "$ker_rel" lt "$cur_rel" && sudo apt-get remove "$kernel"

If you have any version that is newer than the current one this will give you a warning to restart you computer first. Also note that the older kernels are preserved due to a good reason which is if you somehow mess up your current kernel making your system unstable then you should be able to boot into any older kernel.

share|improve this answer

I don't want to purge newer kernel than current so I use this :

dpkg -l linux-* | awk -v cur=$(uname -r) '
  /^ii/ && /linux-image(.*)-[0-9\.\-]+/
    match(cur, /([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)/, v);
    match($2, /([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)/, c);
    if ((c[1] < v[1]) || (c[1]<=v[1] && c[2]<v[2]) ||
      (c[1]<=v[1] && c[2]<=v[2] && c[3]<v[3]) ||
      (c[1]<=v[1] && c[2]<=v[2] && c[3]<=v[3] && c[4]<v[4])
    ) {
      print $2;
  ' | xargs sudo apt-get -y purge
share|improve this answer

Just to chime in, you can also issue

apt-get remove linux-{image,headers}-x.y.z-{1,2,...,n}

as root, and the job will be done.

share|improve this answer
  1. Open the terminal.
  2. Type the command sudo su.
  3. Open file directory using xdg-open /boot/ in the bash shell.
  4. Then remove all the kernel files that you don't require.
  5. Give the command update-grub.
share|improve this answer
-1 this does not add anything to askubuntu.com/a/155356/158442 (which was downvoted to -3, if you note), and is just as dangerous. –  muru Aug 31 '14 at 9:19

I'm using a KDE desktop, and the easiest option I found was using the kde-config-grub2 application as suggested here: https://www.kubuntuforums.net/showthread.php?58075-remove-old-linux-versions (which I already had installed for setting background image, default boot option, and the like). Next to the drop-down box where you can choose the default entry, there is a "Remove Old Entries" button. Clicking this button presents you with a list of all installed kernels and you can select which ones to remove. When you apply the changes it will use dpkg to actually remove them from the system as well as the GRUB menu.

share|improve this answer

Open terminal and check your current kernel:

uname -r 


Next, type the command below to view/list all installed kernels on your system.

dpkg --list | grep linux-image 

Find all the kernels that lower than your current kernel. When you know which kernel to remove, continue below to remove it. Run the commands below to remove the kernel you selected.

sudo apt-get purge linux-image-x.x.x.x-generic 

Finally, run the commands below to update grub2

sudo update-grub2 

Reboot your system.

share|improve this answer
When doing this in 10.04 and 12.04, I found update-grub was automatically run during the purge process. –  aidan Jan 2 '13 at 0:45
bash's brace expansion can be used, e.g. sudo apt-get purge linux-image-3.2.0-3{0..5}-generic (removes 30,31,..,35) –  ajo Mar 19 '13 at 9:04
No need to reboot the system afterward. In fact, you should reboot the system before performing these steps, to ensure you are using the latest kernel version that you probably just downloaded & installed (you did an apt-get update && apt-get upgrade before this, right??) –  Ricket Feb 28 '14 at 2:27
You may also want to uninstall the linux-signed-image packages that may be installed in UEFI systems: sudo apt-get purge linux-signed-image-3.11.0-{12,14,24}-generic which would remove 12, 14 and 24 –  devius Jul 1 '14 at 10:53
@jarno I don't know if I'm using a signed kernel or not, but uname -r doesn't have any signed string on my system. I do seem to have a signed image installed and the output of that ls command is: /boot/vmlinuz-3.19.0-16-generic.efi.signed. –  devius May 13 at 14:38

Try this. Run it as root.

Save this script as, say ./keep-n-kernels.sh

Pass, as a command line argument, the number of most recent kernels you want to preserve.


# pass n as a command line argument, and it will find all the installed
# kernels and keep only the n most recent ones => uninstall all older ones

# dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
# this command gives the list of all packages EXCEPT for the latest kernel.
# source : https://help.ubuntu.com/community/Lubuntu/Documentation/RemoveOldKernels


# find the installed kernel versions :
# dpkg-query -W -f='${Version}\n' 'linux-image-*' | grep . | sort -n
# gives version numbers, one in each line
# dpkg-query -W -f='${Version}\n' 'linux-image-*' | grep . | sed 's/\...$//g' | grep -v '\...$'| sort -u
# gives only the ones that appear in linux-image

# suffix, e.g. -generic-pae
# the kind of kernel you boot into
suffix=$(uname -r | sed 's:^[0-9]\.[0-9]\.[0-9]\-[0-9]\{2\}::g')

command="apt-get purge "

for version in $(dpkg-query -W -f='${Version}\n' 'linux-image-*' | grep . | sed 's/\...$//g' | grep -v '\...$'| sort -u | head -n -${n})
    command=${command}"^linux-image-${version}${suffix} "


Sample usage :

# ./keep-n-kernels.sh 4 # launch the apt-get command to remove all but the 4 most recent kernels

If you want [AND AT YOUR OWN RISK], you can add a -y (or a force flag) to the apt-get command and make it non-interactive.

share|improve this answer

To have a bit more control over which versions to keep, explicitly select the ones you want to remove. For instance if you want to remove kernel versions 3.2.0.[49-53], use a simple for loop:

for k in 49 51 52 53 ; do aptitude remove --purge linux-image-3.2.0-${k}-generic ; done

Adjust the list of kernel versions to fit.

share|improve this answer

The following string of commands will purge any installed linux kernels except the currently running one (grep -v uname -r) and the lastest available kernel (dpkg -l | .... | tail -1):

dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 | grep -v `dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 | tail -1` | grep -v `uname -r` | xargs apt-get -y purge

I use this to keep desktop's boot volumes relatively clean, but in a server situation you'd probably want to expand the logic and write some additional scripting to maintain a list of the last X kernels the server has booted.

Something like a startup script that does:

uname -r >> /root/bootedkernels
cat /root/bootedkernels | sort -u | tail -3 > /root/bootedkernels # Keep the last 3 booted kernels

and then use:

dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 | grep -vf /root/bootedkernels | grep -v `dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 | tail -1` | grep -v `uname -r` | xargs apt-get -y purge
share|improve this answer

Here's the script I use to keep 2 kernel packages installed (i.e. the current one and the previous one). It also removes the initrd-VERSION-generic.old-dkms files left around by DKMS, which can fill-up a small boot partition.

The script:

echo "**Removing -generic.old-dkms files from /boot**" && rm -f /boot/*-generic.old-dkms # if using DKMS it creates initrd-VERSION-generic.old-dkms in /boot and doesn't clean them up, meaning after a few kernel upgrades /boot can become full
OLDKERNEL=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | awk '{print "linux-image-" $0}')
OLDHEADERS=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | sed 's/-generic//g' | awk '{print "linux-headers-" $0}')
OLDHEADERS=${OLDHEADERS//-pae/} # remove -pae string as linux-header packages don't have it in their names
if [ -n "$OLDKERNEL" -o -n "$OLDHEADERS" ]; then
apt-get -q remove --purge $OLDKERNEL $OLDHEADERS
echo "**Finished removing old kernels**"
echo "**No old kernels found**"
share|improve this answer

Based on a previous answer by David Kemp, the following script will purge all headers and images except for the last 2 versions.

# This script assumes that the installed linux-image and linux-headers packages
# share the same versions (i.e. if a linux-image version number is installed,
# the corresponding linux-headers package will also be installed, and vice
# versa.)

SECONDTOLASTVER=$(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -r -n | sed '/^[^0-9]\+$/d' | sed 's/^.*-\([0-9\.]\+-[0-9]\+\).*/\1/' | uniq | sed -n 2p)

# get a list of package names matching the argument passed to the function, and
# return only those package names which should be removed
get_pkgs_to_remove_matching () {
    if [ -n "$SECONDTOLASTVER" ]; then
        echo $(dpkg --list | grep $1 | awk '{ print $2 }' | sort | sed -n '/'"$SECONDTOLASTVER"'/q;p')

echo $(get_pkgs_to_remove_matching linux-image) $(get_pkgs_to_remove_matching linux-headers) | xargs sudo apt-get -y purge
share|improve this answer

Install the synaptic package manager and go down to the filters tab (I think filters, if not try all 5) and select "local". This will show you orphaned packages on your system, such as the kernels. After you uninstall them, run update-grub. That command updates the list of boot options for grub.

If this fails, you can always try apt-get remove linux-image-version-generic.

share|improve this answer

The fastest/simpler way (Applicable at least since 12.04) possible that already comes with Ubuntu is apt-get. Do the following if you wish to remove all older kernel versions that are not in use (Except the previous one that you are no using. This is to make sure that if the current kernel version fails in some way, you have a way to go back to a previous state). Do the following:

sudo apt-get autoclean

This will eliminate any old files (Including kernel versions) you may have. Note that if you have many old versions, it will take a while since it has to make sure that removing the kernel version has no issues. For me, removing the last 12 kernel versions took about 2 minutes. You can also do the following:

sudo apt-get clean

Which will eliminate everything downloaded and stored in the cache folder of apt. Lastly you have:

sudo apt-get autoremove

which would check for any unused packages and remove them if necessary. This is great for those libraries and dependency packages that are no longer needed byt any app installed.

share|improve this answer
I can confirm that sudo apt-get autoremove does remove old (more than one version ago) kernels in 14.04. You may have to run it before and after upgrading your kernel. When I ran before upgrading, it only removed the old kernel's generic version. Then, after upgrading my kernel, it removed the old kernel's lowlatency version, as well. –  tekNorah May 16 at 20:24
Yes, this worked beautifully for me, cleaned up all old kernels properly, and does not rely on crazy one-line scripts! Recommended, wish I could upvote this more than once! –  Jeff Atwood Aug 8 at 5:59

Personally, I like using Synaptic. It makes me feel more secure about what's going on. The only app I've used that has an option to remove old kernels is Ubuntu Tweak.

How to remove the kernels you are not using:

  • Open UbuntuTweak
  • Click on 'Package Cleaner' under 'Applications' in the left-hand pane
  • On the right side of the 'cleaning view' press 'Clean Kernels'
  • Select all kernels - I think the one in use is not listed but just in case check running uname -a in a terminal
share|improve this answer

An easy way to get rid of almost all obsolete packages, packages no longer in any package list, along with obsolete kernels is to do one of the following:

dpkg --purge $(aptitude search ?obsolete)

However, this will miss packages that are still recommended by other packages, and the -R/--without-recommends argument does not resolve this problem.

dselect after switching sort mode with 'o' will show all obsolete packages including the ones aptitude misses, but some people don't like using it.

share|improve this answer

You can follow the Using the "unattended-upgrades" package section of Automatic Security Updates article on Ubuntu Wiki to perform this.

You need to change the following line in /etc/apt/apt.conf.d/50unattended-upgrades file;

//Unattended-Upgrade::Remove-Unused-Dependencies "false";


Unattended-Upgrade::Remove-Unused-Dependencies "true";

to automatically remove old packages, including kernels.

Also remove or comment the line


in the "NeverAutoRemove" section of the file /etc/apt/apt.conf.d/01autoremove.

share|improve this answer
I did this but it was still collecting 3+ old kernels consuming 100's of MBs. So I added apt-get autoremove to my daily cron job that actually does the upgrades, since it doesn't always go through built-in update-manager. –  Marcos Aug 24 '12 at 12:01

Backup your GRUB configuration file which is in /boot/grub/grub.cfg which we will need if something goes wrong.

Open Terminal CTRL+ALT+T. You need to be the root. For that :

sudo -i

Now we want to edit the file. For that:

gedit /boot/grub/grub.cfg

You will get GEDIT window.

Now search for ### BEGIN /etc/grub.d/10_linux ###.

After that line you will see the items of your GRUB.

So if we want to remove Ubuntu, with Linux 2.6.32-30-generic from GRUB, Remove the red highlited line in the image.

screenshot showing the contents of /boot/grub/grub.cfg

You should have got the idea of removing items from GRUB.

After editing the file save it.

Do as you like but be careful not to remove other lines.


  • NOTE


When kernel is updated the /boot/grub/grub.cfg is recreated. So the older kernels will be visible again. You have to do this every time you run the command update-grub and after updating the kernel.

Source (my blog): How to remove a item from GRUB boot menu

share|improve this answer
Thanks for the edit. Ubuntu has used GRUB2 since 9.10, so it's unlikely any solution that would work for any version since then would fail for any other version. (Thus, if this works for 10.04, it probably works for later versions too.) Unfortunately, because it's GRUB2, this will probably not work at all, or at least not for very long. The file you're editing, /etc/grub/grub.cfg is automatically recreated when update-grub runs--and it is run every time there is a kernel update (and for some other updates). –  Eliah Kagan Jan 30 '13 at 13:10

in addition to the above answers you could try to remove the kernel image + system.map + config files manually. grub looks for those files in the /boot directory.

remove any files not related to the kernel version(s) you use. if you are using only the latest version, let's say 3.2.0-25, it should be safe to remove all 2.6.* and 3.0.* versions. so you type ls -alF /boot/2.6. to see what's there and remove those. same with all the other versions except the one(s) you are using.

NB: when updating the kernel it may be good policy to keep the version that previously worked best for you

share|improve this answer
This seems likely to break things, particularly when 3rd party modules have been installed. –  leonardo Apr 1 '13 at 15:24

Removing Entries from Grub 2 Entries should be removed by editing or removing files in the /etc/grub.d folder. The /boot/grub/grub.cfg file is read-only and should not normally require editing.

Too Many Kernels?

  • If you are not sure of the kernel you are currently using, in a terminal type uname -r.

  • Kernels removed via APT (Synaptic, "apt-get remove", etc.) will automatically update grub.cfg and no user action is required.

  • A great tool for removing kernels (and menu entries) is Ubuntu-Tweak, a safe and easy-to-use GUI app.

  • Install ubuntu tweak

  • Ubuntu-Tweak will be available under Applications > System Tools.

Remove Older Kernel Entries

  • Select "Package Cleaner" on the left and "Clean Kernel" from the right panel.

  • Press the "Unlock" button at the lower right, enter your password.

  • Select from the displayed list the kernel images and headers you wish to remove. The kernel in use is not listed.

  • Press the "Cleanup" button at the lower right to remove the selected kernel images and headers.

Remove Operating Systems from the Grub menu

  • Other Operating Systems which have been removed from the computer will also be removed from the menu once "update-grub" is run as root.

  • Menu items are placed on the Grub2 menu by scripts. If you don't want other Operating Systems to be entered in the menu, disable /etc/grub.d/30_osprober

  • Run this command to stop the script from running
    sudo chmod -x /etc/grub.d/30_os-prober

  • DISABLE_30_OS-PROBER='true' in /etc/default/grub

Remove Memtest86+ from the Grub Menu
sudo chmod -x /etc/grub.d/20_memtest86+

  • Run the update-grub command to allow the changes to be incorporated in grub.cfg


Note: After kernel updates a new entry is added to the GRUB menu.You can remove the older one if you want.However, most experienced users will advise you to keep at least one spare entry in case something goes wrong with an upgrade and you need to boot an older kernel version for troubleshooting purposes.

Alternate way to remove Kernel entries (prior to 10.04)

for GRUB not GRUB2

startupmanager Install startupmanager

You can find it under System>>Administration>> alt text
alt text
You see in the second screenshot you can select how many kernels to show? I generally just keep it on 1, but when I get a kernel upgrade I always change it to 2 before restarting so I can select the older kernel if the new kernel has problems with my hardware. Once I know the new kernel is working well I change it back to 1.

share|improve this answer
Actually, startupmanager dint give me a window like this on Ubuntu 10.04, instead it just gave a window with two tabs -> Boot options and Advanced.. and in advanced it dint have the option to limit the number of kernels. So please update the answer for Ubuntu 10.04.(And thats why i down-voted this..) –  Sen Dec 13 '10 at 5:12

10.04 GUI Method

Computer Janitor can clean up old kernels and I believe is installed by default in Ubuntu (but not Kubuntu).

GRUB 1, if you're using that, has an option in /boot/grub/menu.lst to specify how many kernels it should show at a maximum. GRUB 2, as far as I can tell, does not.

share|improve this answer
Computer Janitor should not be used - it is buggy and has now been dropped as a default application in natty/oneiric/precise. –  fossfreedom Feb 13 '12 at 16:04
Rather, install "Ubuntu Tweak" as described in another answer (its own ppa), which has its own "computer janitor" (not to be confused with the "computer janitor" that temporarily was available in older ubuntu versions) –  michael_n Feb 4 '13 at 2:10

I disabled the 10_linux boot file and put custom entries in 40_custom (copied/pasted from boot.cfg). That way you can edit the text of the entry carefully. Although updating your kernel may not update your 40_custom file, so you may have to beware of that. Although it's easy to fix.

share|improve this answer

protected by Community Aug 2 at 6:05

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.