Creating a full system update alias command

Hello there! Today I was wondering if I could perform a full system update faster. I use packages from the AUR and flatpak along with Arch official packages. So I came up with this simple solution:

We’re going to create an alias command that will be remembered after every login and that performs a full system update (including AUR and flatpak).

First of all, we’ll open our .bashrc file

nano /home/YOUR_USERNAME/.bashrc

Then at the bottom of it, let’s add our command

alias YOUR_ALIAS='yay && flatpak update && flatpak uninstall --unused'

*Notice you could use any word here as your alias.

Next step is to save with Ctrl + O and close the file with Ctrl + X. And that’s it! you can close your terminal or try your new alias: to do so, just type it in; it will ask for sudo password, and do its job.

As you might have figured out by now, the alias combines ‘yay’ (that will perform ‘yay -Syu’ wich is similar to pacman -Syu + updating packages from the AUR) and ‘flatpak update’ (wich will update flatpak packages); then ‘flatpak uninstall --unused’ (it will uninstall old flatpak packages no longer in use) - Thanks @Beardedgeek72 for this last command!.

Creating the alias and saving it to .bashrc will make it available any time you open a terminal.

And that’s it for now, I hope you find it useful!

Don’t use sudo to edit files that your user owns.

If you want to automate “all the things” then people generally recommend topgrade.

(Personally I’d rather stick to running updates myself, when I want to, but “different strokes for different folks”…)

9 Likes

This cannot be stressed enough.

Even more generally: never use sudo if the command works without it (or if it the desired effect can be achieved by using some other command that does not require sudo).

For example, don’t use sudo yay, since just yay works.

This is not only due to the fact that it is unnecessary, but more importantly, because it is potentially harmful. In the previous example, yay does not only install packages, but also builds them. Building packages as root can cause problems.

If you must use sudo, it’s a good idea to try to minimise the reach it has, for example: instead of sudo reflector --save filename you can get away with reflector | sudo tee filename (since tee is a minimalist utility that does nothing but write to a file what it receives in stdin, while also printing it to stdout – much leaner than reflector, a utility that connects to the internet).

In your home directory, you never need to use sudo, since you should own all the files there (if you don’t, you’ve done something wrong in the past). Using sudo just puts you at risk of polluting your user space with root owned files. This is also one of the reason why you should never run a GUI program with sudo.

It is a good idea to develop a sort of fear of using the sudo command. Not in the sense of: “I’m scared to do anything with sudo”, but in the sense of: “oh, I’m using sudo, I better be extra careful now!”… like a positive, productive sudophobia. Treat it like a dangerous power tool (like a circular saw, for example).

2 Likes

Thanks for the reply! I use sudo just when necessary, but I don’t know why, every time I edited .bashrc I am used to use sudo. Those are the things that one do without thinking for many years and never change.Well it’s time to change, I’ll edit the post so people won’t damage their system. Thank you very much!

Thanks I’ll edit it out, you’re absolutely right about sudo!

This is what I generally use. Topgrade works very well!

I didn’t know about topgrade, I’m reading about it, I’ll give it a shot! Thanks

[Edit] I didn’t really liked topgrade, as it makes the process a bit more involved and longer. It’s a powerful tool and I appreciate it, but I would use it once in a while. I’ll stick with my alias for everyday use, since it’s pretty fast and dirt simple!

You are right, it is just an alias and I got my wires crossed, disregard my post.

2 Likes