Linux

Keep linux up to date: the right way to update your repositories

When it comes to installing applications and programs in Linux there are several ways to do it. More advanced users can choose to download the source code from the developer’s website and compile it directly on their computer. Something very slow and impractical actually. The most inexperienced users tend to take the easy way: find and download the binary (for example, the deb) and install it, from the package manager, by double clicking. Like in Windows. And thirdly, we have the intermediate users who are looking for convenience and ease and make use of the Linux repositories to download, install and update their programs.

What are Linux repositories?

The repositories are one of the best features that Linux. A repository is a list of programs, generally always updated, that allows us to easily search and download all kinds of programs and tools in our distribution.

Thanks to the repositories we will be able to have a safe and reliable place from which to download software and the latest updates for all our programs. These programs will be installed without any type of dependency problem, and we can also update our entire repertoire of programs with a simple command.

The developers of the distros usually include their own repositories with useful programs. In addition, many developers maintain their own independent repositories to distribute their programs. Even any user can create and maintain their own repository, very useful, for example, to distribute software lists.

Different types of repositories in Ubuntu

When we install Ubuntu, the distro installs a series of repositories belonging to different channels:

  • Main: the repository installed by default. It consists of free FOSS software that can be distributed freely and without restrictions.
  • Universe – Includes free and open source software, but cannot guarantee regular security updates.
  • Multiverse – Includes software that is from FOSS. It should be the user who analyzes the licenses and decides whether or not they can use these programs legally.
  • Restricted: within this channel we can find closed source software. It is used, for example, to distribute NVIDIA drivers, among many others.
  • Partner – Includes proprietary software that has been packaged by Canonical.

And in addition to these repositories, we can also add third-party repositories to our Linux distro to install other software safely.

The steps that we are going to see below have been done on Ubuntu, but they should be the same for any Debian-based distro.

How to add new repositories to the software list

To see the list of repositories that we have in our Ubuntu distro, what we must do is open a Terminal (Control + Alt + T) and execute the following command in it:

sudo gedit /etc/apt/sources.list

In case it doesn’t work, or we don’t have gedit installed in our distro, we can do it with the next one, going to the «nano» editor.

sudo nano /etc/apt/sources.list

As we will see, a list will be opened with all the repositories that we have in our distro. Repositories (for example, deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted) that start without # are the ones in use. On the other hand, those that appear at the beginning with a # are those that we have installed, but are disabled.

If we want to add a new repo, we just have to add it, as follows, at the end of the text file:

deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

We save the changes and that’s it. Of course, before updating the repositories and installing any program we must install the security keys of said repository. These are usually offered together with the PPA, and next we are going to see an example with the official Google Chrome repo.

Example to add Google Chrome repository from Terminal

To add a Linux repository, or PPA, from the terminal , we must do it as follows. The first thing to do will be to search the Internet for the repository we want to add. In the case of Google Chrome (this example), we can find it on the Google website .

In the terminal, we will execute the following command to add the keys of the official Google repositories to our Linux. Otherwise, the software in the repositories cannot be validated and will return an error:

wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

Once the previous command has been executed, we can now add the repository to the Ubuntu list of repositories. And we will do that with the following command:

sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'

Obviously, if we have added the repository from GEDIT as we have explained in the previous step, this last command will not be necessary.

Now, first of all, we will have to update the list of Linux repositories to register all the programs on our system and be able to download and install them with apt install.

How to update the Linux repositories list

If we have already added the repositories we want to the list with the previous steps, or we simply want to update our software without adding new repositories, the process is much faster.

The only thing left to do is open a Terminal (Control + Alt + T) in our Linux and execute the following two commands:

  • sudo apt update (to update the repositories software lists).
  • sudo apt upgrade (to download the packages that are available).

When the process is finished, all our Linux programs, which have been installed through the repositories, will have been updated to their latest version.

We can now install the programs we want from our Linux repositories using apt install (for example: sudo apt install google-chrome).

How to delete a Linux repository

Maybe with the passage of time we no longer need a Linux repository in our distro. Either because it has become part of the official repositories of it, or simply because we no longer use the program.

It can also happen that the repository has stopped working and, because of it, we are having errors when updating the software lists or updating our Linux distro.

To delete the repository, what we must do is open the list of software repositories with the following command:

sudo gedit /etc/apt/sources.list

The gedit text editor will open with the list of all the repositories that we have added. We simply have to locate the repository that we want to delete and remove it from the list. We can also comment it with pads, such as comments, so that it is disabled.

The repository is already removed. Now updating the list with sudo apt update and the changes will be reflected in our distro.

Remove PPA

In case we have added the repository through a PPA, removing it is quite a simple task. The only thing we will have to do is execute the following command in the terminal, adding the URL of the PPA that we want to remove at the end:

sudo add-apt-repository -r ppa:repo/repo

If the repository had a key associated with it, we can remove it using the command “sudo apt-key del” followed by the numeric key in quotes or its last 8 characters (without quotes).

We update the list of software with “sudo apt update” and that’s it.

Problems updating Linux repositories

Although the normal thing is that everything goes well, and in a few seconds we have the updated software lists, there can be several reasons why the repos are not updated correctly. When this happens we must not lose our cool, since with a couple of simple commands we will be able to solve most of the problems.

Sub-process / usr / bin / dpkg error

This error message usually appears when a pending installation has been left. The dpkg binary has been locked and therefore other commands that depend on it cannot be executed. In that case, what we should do is try to complete these updates by executing in the terminal:

sudo dpkg –configure -a

If after this the problem has not been solved, then we will have to delete some files that may be the ones that are causing problems. From a terminal, then we must execute:

sudo rm /var/lib/dpkg/info/*.postrm && sudo rm /var/lib/dpkg/info/*.list

So, we will clear the cache and start updating the repos with:

sudo apt-get clean all && sudo apt-get update && sudo apt-get upgrade

Something went wrong, run sudo apt-get -f install

This error message is also one of the most common that we can find. As we can see, it is very descriptive, and it explains to us in its own name how to solve it. Therefore, the first thing we will have to do is execute this command to solve the problem with the update manager or with the software center that is blocking the repositories.

sudo apt-get -f install

Once executed, then we can update the Linux repositories and the software lists by executing in the terminal:

sudo apt-get update && sudo apt-get upgrade

Error “unable to find universe / binary-1386 / Packages”

This error usually appears because, at some point, we have executed the command “dpkg –add-architecture 1386” in our distro. This command contains a typo in 1386, where it should be i386. And thus it makes the repositories stop working.

We can check if this is the cause of the problem by executing the following command in our distro:

dpkg --print-foreign-architectures

If this returns the value “1386”, then this is the problem. And we can fix it as easily as running the command:

dpkg --remove-architecture 1386

Now we can update the repos with apt update and reinstall programs without problems.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button