DEV Community

Heiker
Heiker

Posted on

Slightly easier package managing in Debian

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
Enter fullscreen mode Exit fullscreen mode
  • refresh

Update and refresh the local package database.

sudo apt update
Enter fullscreen mode Exit fullscreen mode
  • search

Search for packages in the repositories.

apt search [args]
Enter fullscreen mode Exit fullscreen mode
  • info

Display information about a package in the repositories.

apt show [args]
Enter fullscreen mode Exit fullscreen mode
  • install

Install packages from the repositories.

sudo apt install [args]
Enter fullscreen mode Exit fullscreen mode
  • remove

Remove packages, including its settings and dependencies.

sudo apt purge [args] && sudo apt autoremove
Enter fullscreen mode Exit fullscreen mode
  • remove-just

Remove packages, keeping its settings and dependencies.

sudo apt remove [args]
Enter fullscreen mode Exit fullscreen mode
  • clean-cache

Remove all cached versions of uninstalled packages.

sudo apt-get autoclean
Enter fullscreen mode Exit fullscreen mode
  • destroy-cache

Completely remove all packages from the cache.

sudo apt-get clean
Enter fullscreen mode Exit fullscreen mode

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
fi

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

# ... more and more commands
Enter fullscreen mode Exit fullscreen mode

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).

Top comments (0)