# How to remove old packages on Linux

2023-09-22

This is a short Linux tutorial of incantations you can use to remove dependency packages for programs that you've uninstalled. As far as I know, this is not done automatically on any distros I've used. I tend to run this periodically, most especially after removing software from the command line. Most obviously, you'd do this to reduce your disk usage. 

So here's how I remove old unused dependencies after I remove a package or program from my computer.

In general, autoremove means to remove no-longer needed dependencies. clean on Debian-based systems means to remove the deb dependency file listing and packages. If you are planning on reinstalling the software in the future, it's faster for your package manager to re-use the dependencies locally than re-download them. Personally, I don't need that.

### Debian, Ubuntu and derivatives

```
sudo apt autoremove && sudo apt clean
```

### Void Linux

I use the vpm package to easily install and remove software on Void Linux and this is what I do:

```
sudo vpm cleanup && sudo vpm autoremove
```

For straight up xbps without vpm I'd do the following:

```
xbps-remove -oO
```

This should be equivalent to the vpm commands above.

### Flatpak

In addition to Void's repos I use flatpak for software not found in my distro's repo. To remove unused dependencies you run:

```
sudo flatpak uninstall --unused
```

### Removing old kernels

This is Void-specific for me. After testing an updated kernel to make sure it's stable (have never had a problem on Void linux) I run the following to see which old kernel(s) I have installed:

```
vkpurge list
```

I usually leave one old kernel around just in case I ever have issue and need to use a previous kernel.

To remove an old kernel you run:

```
sudo vkpurge remove <kernel-number>
```

### Node.js npm package

To remove old unused dependencies of a project:

```
npm prune
```

### Python pip/pip3 packages

Like everything else with Python there is no single way to remove unused dependencies that I can see.

Annoyingly, it looks the most recommended way I've found is to install a new package, pip3-autoremove. 

=> https://pypi.org/project/pip3-autoremove/ pip3-autoremove package

I'm not much of a python user and not a fan of its fractured dev enviornment so you'll want to look further into other solutions yourself.

### luarocks

See what luarocks packages you have installed:

```
luarocks list
```

Remove an individual rock:

```
luarocks remove --local <rockname>
```

Removing all installed rocks requires you specify the 'tree' explicitly:

```
luarocks purge --tree=~/.luarocks
```

=> ./index.gmi Back to index

---

If you have a comment you can email lettuce at the ctrl-c.club domain and please put comment and the post name and your handle. 
