To keep your Ubuntu system updated, you can use the apt package manager, which is the default package manager for Ubuntu. You can update both the software and its dependencies using the following commands:
Update Package Lists:
This command updates the local package list from the repositories.
sudo apt update
Example:
$ sudo apt update
Output:
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
...
Upgrade Installed Packages:
After updating the package lists, you can upgrade the installed packages to their latest versions.
sudo apt upgrade
Example:
$ sudo apt upgrade
Output:
The following packages will be upgraded:
...
Do you want to continue? [Y/n]
Type "Y" and press Enter to confirm the upgrade.
Dist-Upgrade (Optional):
If there are major package updates or distribution upgrades available, you can use the following command:
sudo apt dist-upgrade
This command is not needed as frequently as the apt upgrade command. It is typically used when you are upgrading to a new Ubuntu release.
Autoremove (Optional):
To remove packages that were automatically installed as dependencies but are no longer needed, you can use the following command:
sudo apt autoremove
Example:
$ sudo apt autoremove
This command helps keep your system clean by removing orphaned packages.
By running these commands regularly, you can keep your Ubuntu system and its software up to date, which is essential for security and performance. Make sure to use sudo to run these commands with administrator privileges.
Install Dependency
Install Dependencies
Ubuntu uses apt (or the Advanced Package Tool) for software package management. Most of the time, you will see the apt-get command used whenever you see the installation of something on Ubuntu. The main task of apt-get is to retrieve the information and packages from a repository with secure, authenticated software sources used to installation, upgrade, and/or removal of packages along with their dependencies.
This is the syntax of apt-get:
root@host:~# apt-get [options] command
or
root@host:~# apt-get [options] install|remove pkg1 [pkg2 ...]
or
root@host:~# apt-get [options] source pkg1 [pkg2 ...]
Now that we know what apt-get is and how the syntax for it should look like, let’s go through some of the most used apt-get commands, and we will explain how each of them manipulates dependencies.
Install Software
So let’s say that we want to install Python on our server. First, we would need to install a libpython2.7-minimal package/dependency. We can run this command to accomplish this.
root@host:~# apt-get install libpython2.7-minimal
We will get an output that the package itself has been found, unpacked and configured. Along with the info about disk space that package will take. If we are missing two dependencies, then we can just run a command like this to install those packages.
root@host:~# root@host:~# apt-get install libpython2.7-minimal libpython-stdlib:amd64
Now we can install python with pretty much the same command:
root@host:~# apt-get install python
Removal Software
If we want to remove this dependency, we can run the following command.
root@host:~# apt-get remove libpython2.7-minimal
This will remove libpython2.7-minimal package as well as all the associated dependencies it has.
Update Software
If at any point you want to update all the system packages on the server, we can simply run this command. This command updates all of our software including any dependencies.
root@host:~# apt-get update
Or
root@host:~# apt-get upgrade
The second command will list all software packages it wants to install/update and will prompt us with a yes or no option before proceeding with the installation. Using this command, we ensure all of our dependencies are met.
List Software
If you want to list all available packages, we can use this command.
root@host:~# apt-cache pkgnames
We mention this command as it leads us into our next section specifically regarding dependencies. This command will show us a huge list of packages available for installation. Now, let’s say that we want to install the libslang2 package, but are unsure which dependencies need to be installed along with this package and which ones are not. We may not even know which ones we need. Luckily, Linux provides for this option by using the showpkg flag. We can run this command to see what dependencies are needed.
root@host:~# apt-cache showpkg libslang2
So, if we are not sure which dependencies we need, we can simply run the showpkg subcommand to get the information that we need.
Clean Dependencies
If you want to clear up some of the clutter that can sometimes take up our valuable disk space, we can use the following command to free up additional disk space.
root@host:~# apt-get clean
root@host:~# apt-get autoclean
These commands will get the job done for us in the same manner that the yum clean and yum cleanall commands do on CentOS.
The clean flag removes all the .deb files from the local repository in /var/cache except the lock files.
The autoclean flag also removes all the .deb files from the local repository, but unlike the clean flag, it removes only the obsolete packages that can no longer be downloaded.
Unmet Dependencies Errors
Almost every Ubuntu user has seen the error "The following packages have unmet dependencies issues". In this circumstance, the failure almost always is related to the apt package manager as opposed to the software being installed. Luckily, there are multiple options available to rectify this situation. We will look at several ways to address this issue.
Backup Configuration Files
First, as with any system modification, taking a backup of our configurations is a must. We do this to ensure that is any additional issues crop up, we can revert the changes we have made to restore our system files.
root@host:~# cp /etc/apt/sources.list /etc/apt/sources.list.bak
root@host:~# cp /var/lib/dpkg/status /var/lib/dpkg/status.bak
Options
When these dependency errors occur, we have multiple options we can try to address the issue.
Enable all repositories
Update the software
Upgrade the software
Clean the package dependencies
Clean cached packages
Remove "on-hold" or "held" packages
Use the -f flag with the install subcommand
Use the build-dep command
Test install package
Reinstall the software
Remove the PPA
List Packages Using Apt-mark
As an aside, when the apt-mark showauto command is used, it prints a list of each package that will be automatically added on a new line. If a package name is given, only those packages that will be installed automatically will be shown. We mention this, so we can note the packages that should be installed with the software.
root@host:~# apt-mark showauto softwarename
Option 1: Enable all Ubuntu Repositories.
Utilizing this option will allow for a wider base of software and dependencies to pull from. Then, once this is updated, we can try to reinstall the software.
root@host:~# add-apt-repository "deb
http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
root@host:~# apt-get update
Option 2: Update the Software
Once the above command has finished, we can try to update the package again. Trying to update the software should be our first line of defense.
root@host:~# apt-get update softwarename
Option 3: Upgrade the Software
Next, we can show the packages that need to be upgraded and then attempt to upgrade the software.
root@host:~# apt-get -u && apt-get upgrade
Option 4: Clean the Package Dependencies
A corrupted package database or packages that were broken or not installed properly can cause this problem. This option uses the autoremove flag to address this.
root@host:~# apt-get autoremove
This command will remove only obsolete or unnecessary packages that no longer exist in the repositories.
Option 5: Clean Cached Packages
This command will clean up the local repository of downloaded packages. Then, try to reinstall the software.
root@host:~# apt-get clean
Option 6: Remove "On-hold" or "held" Packages
To locate software that is held or on hold, we can use the apt-mark command. Once we have that info, we can use the remove and dry-run flags to see exactly what will be removed. Then, try to reinstall the software.
root@host:~# apt-mark showhold
root@host:~# apt-get remove –dry-run softwarename
Option 7: Use the -f Flag
According to the apt-get man page, using the -f (or --fix-broken) parameter will allow the apt-get command to try to correct the broken dependencies issue. Do not use the package name in the command when using -f.
-f, --fix-broken
Fix; attempt to correct a system with broken dependencies in place. This option, when used with install/remove, can omit any packages to permit APT to deduce a likely solution. If packages are specified, these have to completely correct the problem.
The option is sometimes necessary when running APT for the first time; APT itself does not allow broken package dependencies to exist on a system. It is possible that a system's dependency structure can be so corrupt as to require manual intervention (which usually means using dselect(1) or dpkg --remove to eliminate some of the offending packages).
Use of this option together with -m may produce an error in some situations. Configuration Item: APT::Get::Fix-Broken.https://ss64.com/bash/apt-get.html
root@host:~# apt-get install -f
root@host:~# dpkg --configure -a
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
root@host:~#
If you see the 0 upgraded message, this means this command has failed. We are not done yet, though. Let’s try to issue the command again.
root@host:~# apt-get install -f
Option 8: Use the Build-dep Command
Using this subcommand, we can install all the dependencies for 'softwarename'. Then, we can try to reinstall the software dependencies individually.
root@host:~# apt-get build-dep packagename
Option 9: Test Install Package
The --dry-run flag shows us what apt-get would install without actually installing the package. This is useful with the above command. It can also sometimes show the dependency error prior to the software installation.
root@host:~# apt-get install --dry-run softwarename
Option 10: Reinstall the Software
There are certain dependency issues and conflicts which arise that apt cannot solve. When this occurs, apt will save those packages in an ‘on-hold’ state. This means they will not have been completely installed. Removing those software packages may fix the problem and might assist in solving the original issue. The apt-get purge command will remove the program, all the associated configuration files, and any plugins or settings from our system.
root@host:~# apt-get -u dist-upgrade
root@host:~# apt-get --reinstall softwarename
If the output shows any packages in an “on-hold” state, we can go ahead and try to remove them. Once that command completes, run this command to
root@host:~# apt-get -o Debug::pkgProblemResolver=yes dist-upgrade
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Now remove the held packages one at a time by executing dist-upgrade each time, until there are no more held packages. Afterwards, try to re-install your package. Make sure to implement the –dry-run option, in order to stay informed of the consequences:
root@host:~# apt-get remove -dry-run package-name
root@host:~# apt-get remove package-name
root@host:~# apt-get install package-name
Top comments (0)