DEV Community


Slightly easier package managing in Debian

vonheikemen profile image Heiker ・2 min read

If you use debian you probably know apt, I believe it's actually a frontend for other set of tools that debian has to manipulate the packages in your system.

Anyway, apt is great, it's just that sometimes I forget to write sudo before a command and sometimes I forget that I want to use apt purge instead of apt remove. It's this kinds of things I don't want to think about. And usually this is the part where make some cool alias and live happily ever after, but I'm trying something different now. This time I just want descriptive commands. What I did was create pkg script with the following commands.

  • upgrade

Sync with repositories before upgrading packages.

sudo apt update && sudo apt upgrade
  • refresh

Update and refresh the local package database.

sudo apt update
  • search

Search for packages in the repositories.

apt search [args]
  • info

Display information about a package in the repositories.

apt show [args]
  • install

Install packages from the repositories.

sudo apt install [args]
  • remove

Remove packages, including its settings and dependencies.

sudo apt purge [args] && sudo apt autoremove
  • remove-just

Remove packages, keeping its settings and dependencies.

sudo apt remove [args]
  • clean-cache

Remove all cached versions of uninstalled packages.

sudo apt-get autoclean
  • destroy-cache

Completely remove all packages from the cache.

sudo apt-get clean

This way when I say pkg remove [package-name] I'm saying "destroy the damn thing and leave no trace". See how nice that is? I don't even have to think about sudo anymore.

If you're curious how you can do something like this, well you can create a file and start writing your commands.

#! /usr/bin/env sh

# Save the first argument to `cmd`
# and remove it from the argument list
cmd=$1; shift

if [ "$cmd" = 'upgrade' ];then
  sudo apt update && sudo apt upgrade
  exit 0

if [ "$cmd" = 'install' ];then
  sudo apt install $@
  exit 0

# ... more and more commands

You save it then make it executable with chmod +x [name-of-script]. Next step is to put the script somewhere in a folder of your PATH (don't know what they are? Use echo "$PATH") preferably one that is located in your home directory. That's it, next time you open up a terminal you'll have this handy command.

My version of this wrapper is located here. And there is also a version for arch (pacman).


Editor guide