Update Packages in Linux

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

In the realm of Linux, the term Update Package pertains to a fresh edition or release of a software package that can be installed on a Linux system. Here, the term Package refers to a pre-assembled collection of software that includes all the essential files and instructions needed to install and operate an application. Software updates provide the system with access to new features and improvements. In this tutorial, I will explore updating packages in Linux with its importance and learn how to edit the packages in Linux distributions.

Key Takeaways

  • Learning about package management tools in Linux.
  • Achieving knowledge about the importance of updating packages for Linux.
  • Knowing how to update packages in Linux distros.
  • Having the core insight of updating packages and the impact of them in different methods.
  • Getting hints about the upcoming problems you may face while updating packages in your system with solutions.

Requirements

  • You need to have a functioning package manager installed on your system to update packages, such as apt for Ubuntu, Yum for Fedora, etc.
  • As updating packages frequently involves making changes to system files and configurations, it’s badly necessary for the user to have administrative (root) privileges.
  • You must verify that your repository configuration is accurate and the repositories are accessible.
  • You have to accommodate the updates with enough free disk space in your system in case of updating large software packages.

Why Do You Need to Update Packages in Linux?

Software developers distribute updates in the form of packages when they make improvements, fix bugs or apply security updates to their applications, resulting in the release of new versions. It’s healthy and essential to keep packages up to date regularly for several reasons:

  1. Security: Updates consist of security patches to address vulnerabilities. Ensuring your software is up-to-date safeguards your system against potential risks or cyber-attacks.
  2. Stability: Updates improve the stability and performance of your system by addressing and resolving bugs and glitches.
  3. Features: Updates of packages include new features and versions of the software which improves the user experience.
  4. Compatibility: Updating packages ensures the software remains in sync with the most recent libraries, dependencies, and the overall Linux ecosystem.

Linux Commands to Update All Packages in Various Linux Distributions

The Linux commands for updating all packages differ based on the specific package manager employed by each Linux distribution. Below are the update commands for some popular distributions:

1. APT (Advanced Package Tool)

It’s a package management system predominantly for Debian-based Linux distributions including Debian itself, Ubuntu, and Linux Mint.

2. YUM (Yellowdog Updater, Modified)

It is a package management utility for Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and other distros. You can check the following yum commands to update packages in your RedHat-based distros:

A. Check Update

To check available updates for the installed packages on your system you can run the following command:

sudo yum check-update

It’ll query for available updates in the configured software repositories.

B. Update All packages

To update all the packages in Red Hat-Based Linux distributions, you can run the following command:

sudo yum update

C. Update Specific Package

To update a specific package using ‘yum,’ you can run the following command with root privilege:

sudo yum update package_name

After execution of the command, yum will search for an available update for the specific package, and if so, a prompt will appear asking your permission to proceed. You type Y and press ENTER and yum will download and install the latest version of the mentioned package.

3. RPM Package

RPM stands for Red Hat Package Manager. It serves as a package management system that contains tools to install, and upgrade software packages on Linux systems.

To update an RPM package on Red Hat-based Linux distributions, you can execute the following command:

sudo rpm -Uvh package_name.rpm

The -Uvh option serves to either update the package it’s already installed or install it if it’s not present in the system.

4. Emerge

The primary package manager in Gentoo Linux is called “emerge” which serves as the tool for software package installation, updates, and removal. It represents the ultimate command-line interface for the Portage system.

5. zyper

The zyper serves as a command_line package manager designed for SUSE Linx, enabling users to install, update, and uninstall packages on their systems.

6. slackpkg

In Linux, ‘slackpkg’ acts as a package management tool utilized for the management of software packages in Slackware Linux distributions.

In this table, I’ve summarized all the packages for specific Linux distributions to have a compact look.

Linux Distribution Command to Update
Ubuntu / Debian apt/apt-get
Fedora yum
Gentoo emerge
Suse/ OpenSUSE zyper
SlackWare slackpkg
RHEL rpm

In this article, I’m going to demonstrate the process of updating packages specifically in the Ubuntu distribution.

3 Cases to Update Packages in Ubuntu

Updating packages is the most fundamental prerequisite to keeping your system secured and stable. You can update your Ubuntu system’s packages following the three cases described below according to your need.

Case 01: Update a Single Package in Ubuntu

In this section, I’m going to show you how to update any one specific package in the CLI (Command Line Interface) of the Ubuntu distro. You can follow the steps below:

Steps to follow >

➊ Open the terminal in Ubuntu.

➋ At first, check for available updates for installed packages on your system.

sudo apt list --upgradable

EXPLANATION

  • sudo: Grants you the super users’ privilege.
  • apt: It’s a command line package manager for Ubuntu that manages the software packages while installing and updating.
  • list: This subcommand lists out all the packages.
  • –upgradable: It’s an option provided to the command apt list to get the list of packages that have available upgrades.

Listed out the available upgradable packages using sudo apt list --upgradable command.Here, the provided information contains the details of available upgradeable packages.

OUTPUT ANALYSIS

Though it’s huge information, it’ll be easier if I break down the highlighted line from the list:

  • apparmor is the package name with an available updated version.
  • lunar-updates is the Ubuntu version for the updates.
  • 0.8-1ubuntu2.1 refers to the latest version available for update.
  • amd64 is the operating system architecture.
  • 0.8-1ubuntu2 indicates the old package version.

Now, choose the package you need to update from here and follow the rest of the steps to update packages.

➌ Run the command to update a single package.

sudo apt --only-upgrade install python3.11

EXPLANATION

  • sudo: This command allows you to execute a command like the superusers.
  • apt: a package management tool for the Ubuntu distro which manages installing and updating of packages.
  • –only-upgrade: This is an option to the apt command that says that only upgrades should be performed.
  • install: This subcommand tells apt that you want to install a package.
  • python3.11: It represents the name of the package you want to install.

I've only upgraded python3.11 among the listed packages using sudo apt --only-upgrade install python3.11Here, the mentioned package name is python3.11 which has been updated only.

Note: The apt command only updates the already installed package with the option –only -upgrade but it does not install the package if it’s not already installed.

Case 02: Update Selected Packages on Your System

It follows the same path as the single package update with a little modification in the command which is:

sudo apt install --only -upgrade <package1> <package2> <package3>

EXPLANATION

  • sudo: It’s used for getting the root access.
  • apt: This package management tool handles the installation and updating of packages.
  • –only-upgrade: This option indicates that the command will perform only upgrade.
  • <package1> <package2> <package3>: These three are the selected package names you want to update through a single command. You can add more package names if you want. So, replace them with real package names.

Here I've updated three packages of my preference from the upgradable list using a single command sudo apt install cpp-12 evince gdm3.The command will update the specified packages to their latest available version.

Case 03: Update All Packages in Your Ubuntu Distro

To update all the packages that require updates, you can use either CLI (Command Line Interface) or GUI(Graphical User Interface). You can follow both of the methods below.

Method 01: Using CLI to Update All Packages

It’s easier to update all the packages using a single command at the terminal as stated below.

Steps to Follow >

➊ Open the terminal in Ubuntu.

➋ Now, execute the following command to refresh the package index.

sudo apt update

EXPLANATION

  • sudo: Grants root access.
  • apt: Handles actions related to packages.
  • update: This is a subcommand to the apt that tells the package manager to install the latest information on available packages.

I've fetched the latest information about the available packages using sudo apt update command.After examining the output of the above command, check for available updates at the end. If updates are needed, proceed to the next step accordingly.

➌ To obtain available package updates, use the below command.

sudo apt upgrade

EXPLANATION

  • sudo: Grants root access.
  • apt: Handles actions related to packages.
  • upgrade: This is a subcommand to the apt that tells the package manager to upgrade existing packages to their installed latest versions.

Using sudo apt upgrade command, I've upgraded the installed packages.Once you execute the “sudo apt upgrade” command, you might receive a prompt asking you to press “Y” to proceed upgrade process. So, simply press Y and the packages will be upgraded accordingly.

➍ Though it’s optional, you can run the following command to clean up and free disk space by removing unnecessary packages that were installed as dependencies for other software.

sudo apt autoremove

EXPLANATION

  • sudo: This command is used to get the root access.
  • apt: This tool handles actions related to packages.
  • autoremove: This subcommand instructs the package manager to remove any unused dependencies that are not required anymore.

I've used sudo apt autoremove to remove the unused dependencies that have been installed during update.You can also update packages using the ‘sudo apt-get update’ and ‘sudo apt-get upgrade’ commands instead of ‘sudo apt update’ and ‘sudo apt upgrade’ respectively following the steps mentioned above.

There is no functional difference between the ‘sudo apt update’ and ‘sudo apt-get update’ commands as both of them update packages in Linux. It’s just apt command is the newer and user-friendly interface whereas apt-get is the older and more traditional command line tool.

Method 02: Using Package Updater [GUI Tool]  to Update All Packages

If you want to proceed with the updating of your packages at GUI (Graphical User Interface) then follow the steps accordingly demonstrated below.

Steps to follow >

➊ Go to the search bar in the menu and search for “software Updater” and run that.From the search bar in the Menu, I've searched for Software Updater to find the application➋ Software Updater will check whether any packages are available for update or not.I've run the Software Updater application to check for any available updates for installed packages.➌ If any package exists for the update, it will prompt up a box with the following options.Due to available updates on the sytsem, I've pressed the Install Now button to update those softwares.➍ Now select “Install Now”. A pop-up will appear, requesting your password. Enter your password and click “Authenticate.”While progressing with the installation process, the system has authenticated my identity by asking the root users' password.➎ Once the authentication is complete, Ubuntu will begin the process of downloading and installing the updates.After authentication is done, installation proceeds for the packages. After installing the updates, a prompt will appear like the following requesting to restart your system below.Finally, after all the installation of software updates, I've restarted my system to terminate installing updates.Upon successful completion of the above steps, you can now easily update all the packages in your system.

Problems You Might Face While Updating Packages in Linux

To ensure a secure and up-to-date environment, it’s essential to update packages in Linux routinely. But while updating the packages, users may encounter some common problems. Here are some of the issues that may arise while updating packages in Linux:

  1. sudo apt update not working; It specifically indicates the failure of the package manager ‘apt’ to update package lists from the repositories due to some issues.
  2. apt-get not working: It may include a few problems like update failures, package installation issues, dependency issues, software conflicts, and a few more which are interrupting apt-get to function accordingly.
  3. sudo apt-get update failed to fetch: It indicates that the package manager (apt) fails to download the package information from the set repositories.

There exist some common troubleshooting steps to fix the above-mentioned issues:

  • Check for the Right Source Repository URLs: Any inaccurate or outdated repository URLs in the /etc/apt/sources.list files or any files in the /etc/apt/source.list.d/ directory results in any of the issues mentioned above. So, double-check and fix any inaccurate repository URLs if you encounter any of the above problems.
  • Check for Proxy Settings: If you connect your system through a proxy, you have to configure ‘apt’ to use the correct proxy settings. Modify the /etc/apt/apt.conf or /etc/apt/apt/conf.d/proxy file to set up the proxy configuration accordingly.
  • Mirror Issue: You might try to switch to another mirror. Change the mirror URL in the /etc/apt/sources.list file by editing it to another one from the list of Ubuntu mirrors.
  • Eliminate Package List and Re-Fetch: There are situations when the package lists can get corrupted. Try to get the old lists again after clearing them.
  • Temporary DNS Issues: Choose a faster DNS or restart your system or router to fix the problem.

You can also check for firewall or security software, disk space, or other software conflicts that may hinder the apt update command or apt-get command to perform accordingly.

Complementary Information Related to Update Packages in Linux

In the Linux system, though it’s kind of a ritual to update the packages, It’s not always necessary to use the apt-cache regularly. Nevertheless, the apt-cache command becomes more useful and even necessary in certain circumstances, especially for advanced users, and developers. To get Package information, dependency analysis, and troubleshooting, apt-cache keeps an impactful role.

Similarly, setting up a proxy for package updates is crucial when your system is protected by a network proxy or firewall that prevents direct internet access. To download updates and packages from remote repositories for your package manager, proxy setup ensures your connection to the internet.;

A. The apt-cache Command in Linux

In Linux, the ‘apt-cache’ command queries the package cache and is used to look up package names and packages cache which contains metadata about available software packages. It is also used to keep track of software dependencies. apt-cache command allows you to access package information without installing them. Some common apt-cache commands are listed below:

Command The Function of the Command
sudo apt-cache <pkgnames> Lists all the packages installed.
sudo apt-cache showpkg <PackageName> Shows detailed information about a package.
sudo apt-cache show <PackageName> Displays basic information about a package
sudo apt-cache search <PackageName> Searches for specific packages.
sudo apt-cache depends on <PackageName> Shows package dependencies.

B. Configure Proxy for the apt Command

A proxy server serves as an intermediary between your computer and the internet and redirects your network request. You must configure a proxy server with the apt command if your computer is behind a proxy server.  If this is not done, ‘apt’ won’t be able to access the internet or get updates from the repositories.

Conclusion

In this article, I have narrated a comprehensive perspective about updating packages in Linux that includes the necessary commands to update your packages in different distributions of Linux, and three cases of updating packages. This article provides you with an elaborate explanation and solution to some frequently faced problems by users while updating the package. Here, I’ve shown how to update your packages using both CLI and GUI for your convenience. I hope this essay has been worth your time and has given you the perspective you were looking for.

People Also Ask

How to check available package updates in Debian/Ubuntu?

You can check for the available updatable packages on your system in two ways, one is by using the CLI and another one is by using GUI. Using CLI, first, run the sudo apt update command on the terminal and provide the user password to the prompt. Then again run the command sudo apt list –upgradable to get the list of available updates for your packages.

How to check the last Linux update?

To check the last Linux update, you can find the track of package installation and updates on the system log file which is the /var/log/apt/history.log file. Use the following command to check the last update timestamp: cat /var/log/apt/history.log | grep ‘End-Date’ | tail -1

How to check packages in Linux?

You can run ‘apt list –installed’ to get the list of the packages on Ubuntu-based distribution. You can also use the ‘dpkg’ command to list the installed packages on a Debian or Ubuntu-based system.

Where is the apt update cache?

The ‘apt’ update cache files are located in the ‘/var/cache/apt/’ directory on Ubuntu. The directory stores main cache files which are archives, partial, pkgcache.bin, and srcpkgcache.bin.

How do I use ‘apt’ to reinstall?

You can use the following syntax for reinstallation using the ‘apt’ or ‘apt-get’ reinstall command which is sudo apt -reinstall install package_name

Related Articles


<< Go Back to Package Management in LinuxLearn Linux Basics

3.7/5 - (3 votes)
Auhona Islam

Auhona Islam is a dedicated professional with a background in Electronics and Communication Engineering (ECE) from Khulna University of Engineering & Technology. Graduating in 2023, Auhona is currently excelling in her role as a Linux content developer executive at SOFTEKO to provide a more straightforward route for Linux users. She aims to generate compelling materials for Linux users with her knowledge and skills. She holds her enthusiasm in the realm of Machine Learning (ML), Deep Learning (DL), and Artificial Intelligence (AI). Apart from these, she has a passion for playing instruments and singing. Read Full Bio

Leave a Comment