[Fixed] “sudo apt-get update” Not Working in Ubuntu

In Linux, the sudo apt-get update command plays a vital role in maintaining a healthy and up-to-date system. Nevertheless, there are situations where this straightforward command may not perform as anticipated. In case the apt-get update not working, you can troubleshoot the problem in several ways. In this article, I’ll investigate the prevalent factors contributing to potential failures of the sudo apt-get update command and offer guidance on resolving these issues through troubleshooting steps.

How Does “sudo apt-get update” Work?

In the Linux environment, the sudo apt-get update command serves the purpose of refreshing the local package index and fetching the most recent information about the available software packages from the software repositories. It’s important to note that this command doesn’t perform package installations or upgrades; instead, it renews the package cache to inform your package manager about available packages and newer versions. If I precisely break down the command, you’ll get it clearer.

  • sudo: ‘Sudo’ is a utility that allows running commands with elevated administrative permissions, denoted as ‘superuser do’. Employing sudo empowers you to acquire the essential rights required for tasks like updating package repository data and installing or upgrading software packages on your system.
  • apt-get: This is a legacy package management utility employed in Debian-based Linux distributions. It’s used for managing software packages, including installing, upgrading, and removing them. While apt, a more modern and user-friendly tool has gained popularity.
  • update: This specific sub-command instructs apt-get to refresh its package data. Upon executing the sudo apt-get update, it communicates with the designated software repositories, retrieving the most recent details regarding accessible packages, their versions, and their dependencies.

Why Does “sudo apt-get update” not work?

The sudo apt-get update command can face a range of problems resulting in failures, often accompanied by error messages that offer clues about the underlying issues.

Here are some reasons why the sudo apt-get update may not work:

  • Problems with internet connectivity.
  • Errors in repository configuration.
  • Software conflicts.
  • GPG error.
  • Release file issue.

7 Errors and Solutions to Fix “sudo apt-get update” Not Working

When you face issues during the execution of ‘sudo apt-get update’ on a Linux system, it’s crucial to identify and fix these problems to maintain the proper functioning of your package management system. Here are some typical errors and possible ways to address them.

Error 1: 404 Not Found Error with “apt-get update”

This error can occur for Linux users when apt cannot locate or retrieve the release file from a repository. This particular file holds crucial metadata related to the repository, encompassing details about the accessible packages their respective versions, and additional information.shows 404 error message. Here, you can see that the ‘https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu lunar Release’ repository does not have any release file in my Ubuntu.

If a repository’s release file is absent, you can rectify the issue using either the Graphical user interface (GUI) or the Command-line interface (CLI). Here’s how you can tackle this problem, as outlined.

Solution 1: Using GUI to Fix 404 Not Found Error

To fix this “404 Not Found Error” to resolve the sudo apt-get update not working issue use the Software and Updates app from GUI. Here is how:

  1. Open the Menu bar, and find the Software and Updates from the search bar.Search for Software & Updates in the Show Apps.
  2. Run ‘Software & Updates’ application.Click on the Other Software option.
  3. Now, click on the ‘other software’ option.Uncheck the problematic repositories.
  4. Uncheck the repository. Immediately a prompt will appear asking for the user password to authenticate.
  5. Provide the user password.While unchecking the repositories, Authenticate yourself.
  6. lastly, close the ‘Software & Updates’ application and again run the sudo apt-get update command:
    sudo apt-get update

    sudo apt-get update command works accurately after resolving the 404 error.Here, you can see that the sudo apt-get update is working properly.

Solution 2: Using CLI to Fix 404 Not Found Error

To fix this “404 Not Found Error” to resolve the sudo apt-get update not working issue you can also use the CLI. Here is the full process:

  1. Open the terminal in Ubuntu.
  2. Run the following command:
    sudo add-apt-repository --remove ppa:deadsnakes/ppa

    Removes the problematic repository using the command.

    EXPLANATION
    • sudo: Gives the permission to execute commands with superuser(root) privilege.
    • add-apt-repository: Used to manage APT repositories specifically to add new repositories.
    • –remove: This option tells ‘add-apt-repository’ to remove the mentioned repository in the command rather than add it.
    • ppa:deadsnakes/ppa: Refers to a PPA maintained by the deadsnakes team which provides updated Python packages and I want to remove it.
  3. Now, run the sudo apt-get update command to check whether it’s working or not:
    sudo apt-get update

    Runs apt-get update command to check if it's working or not.Here, you can see that the sudo apt-get update works accordingly after all the necessary modification is done.

Error 2: Failed to Fetch Error

The ‘sudo apt-get update’ can face the ‘failed to fetch’ error due to conflicting software or repositories which hinders the ‘apt’ from fetching the update package information from the configured repositories.shows 'failed to fetch' error while running sudo apt-get update command

Solution 1: Using GUI Remove the Conflicting Software or Repositories

You can use Graphical User Interface (GUI) to solve the “Failed to Fetch” error while updating your system using the sudo apt-get update command through the ‘Software & Updates application. Here are the full steps:

  1. Click on ‘Show Apps’ and search for ‘Software & Updates’.Search for Software & Updates in the Search bar.
  2. Run the Application.After running the application, this prompt appears.
  3. Click on the ‘Other Software’ option.From the 'Other Software' option, uncheck the repositories mentioned in the error.
  4. Now, uncheck the problematic repositories or packages. While doing this, Authenticate yourself by providing the user password.While unchecking the repositories, Authenticate yourself by entering the password. After Authentication is done the unchecked list will be shown.

Here, you can see unchecked packages and now close the window and run the command ‘sudo apt-get update’ to update your system successfully.

Solution 2: Using CLI Remove the Conflicting Software or Repository

To resolve the ‘sudo apt-get update failed to fetch’ situation, you can remove the conflicting software or repositories using  CLI(Command Line Interface). You can follow the steps described below:

  1. Open a terminal in Ubuntu.
  2. Run the following command to update your package list and find out the repositories or software that is causing the error from the error message:
    sudo apt-get update
    EXPLANATION
    • sudo: Provides user the root privilege.
    • apt-get: A command line package management tool that allows users to install, upgrade, and remove software packages.
    • update: A subcommand for ‘apt-get’ that tells to retrieve the latest package information including available updates.
  3. Now, identify the lines that show errors and note down the erroneous repository or software.Shows the problematic repositories in the Failed to Fetch error.Here, you can see the error which includes the repository name and that is https://ppa.launchpadcontent.net/jonathonf/ffmpeg-4/ubuntu/dists/lunar/Release.

  4. After the identification of problematic repositories or software, run the following command to remove them:

    sudo add-apt-repository --remove ppa:repository-name/ppa
    EXPLANATION
    • sudo: Gives users the privilege like root users.
    • add-apt-repository: Used to add new repositories through APT.
    • –remove: This option tells ‘add-apt-repository’ to remove the mentioned repository in the command rather than add it.
    • ppa:jonathonf/ppa: Refers to a PPA maintained by the owners ‘jonathonf’

    The command specifically identifies the PPA owned by ‘jonathonf’ and searches the system’s configuration files (typically in ‘/etc/apt/sources.list’ and ‘/etc/apt/sources.listd/’ ) to find any entries related to the specified PPA. After finding it, it removes the entry from the configuration files.

  5. After removing the problematic software or repository, clean the package cache using the following command:
    sudo apt-get clean
    EXPLANATION
    • sudo: Ensures all the privileges and accesses like the root users.
    • apt-get: A command line package manager for Debian-based Linux distros, used for managing packages.
    • clean: This subcommand tells ‘apt-get’ to remove cached package files from the local package cache.
  6. Finally, run the following command to update the package lists and check whether it’s working or not:

    sudo apt-get update

    Updates the packages using the command.You can see that the update has been accomplished perfectly.

Error 3: Could Not Resolve “archieve.ubuntu.com” Error

This error indicates a DNS resolution problem which means that your system cannot resolve the domain name for the repository.

Solution: Resolve the DNS Issue

To fix the DNS issue, to resolve the sudo apt-get update not working error follow the below steps:

  1. First, check your internet connection and ensure that your connection is stable. If the connection is okay then follow the next steps.
  2.   Now open the terminal and run the following command:

    cat /etc/resolv.conf
    EXPLANATION
    • cat: Used for concatenating and displaying the contents of files.
    • /etc/resolv.conf: It’s a configuration file that is crucial for DNS resolution on a Linux system.

    Concatenates the content from the file.By running the command, you can view the configuration on your system including the IP addresses of the DNS servers that your computer is using. scrolling down, shows the nameserver IP address. In my case, the IP address of the nameserver is 127.0.0.53.

  3. If the file appears empty or misconfigured, you can edit it manually to include a reliable DNS server by running the following command:

    sudo nano /etc/resolv.conf
    EXPLANATION
    • sudo: Used to get the root privilege.
    • nano: This command opens a file and allows the user to edit the file like a text editor.
    • /etc/resolv.conf: It’s the DNS configuration

    Opens the resolv.conf file to change the DNS server.

    Shows the file content to edit.Now, replace the nameserver’s IP address with your preferred reliable DNS server’s IP address such as Google’s DNS (8.8.8.8 and 8.8.84.4). Then save and exit the file by pressing CTRL+O and CTRL+X respectively.

  4. At last, run the following command to check if you can reach the Ubuntu repository by pinging it:

    ping archive.ubuntu.com
    EXPLANATION
    • ping: It checks and diagnoses the network connectivity between your computer and a remote host.
    • ubuntu.com: It’s the hostname of a server within the Ubuntu archive.
  5. Lastly verify your ‘sources.list’ file contains valid repository URLs. To do that run the following command:

    sudo nano /etc/apt/sources.list
    EXPLANATION
    • sudo: Gives the user sudo privilege.
    • nano: Opens a file in the CLI as a text editor.
    • /etc/apt/sources.list: it’s a configuration file that contains repository URLs.

    Opens the sources.list file.

    Shows the file content of sources.list.

Error 4: Hash Sum Mismatch Error

Encountering a “Hash Sum Mismatch” error while running the sudo apt-get update command is not uncommon. This error typically occurs when the checksums of packages downloaded from the repositories do not match the expected values. It can happen for various reasons, including network issues, repository problems, or local caching problems.

Solution: Change the Repository Mirror

To change the repository mirror, try to switch to a different mirror or repository server. Here is how:

  1. Open the file ‘/etc/apt/sources.list’ using the following command and modify the server:
    sudo nano /etc/apt/sources.list
    EXPLANATION
    • sudo: Provides root privilege.
    • nano: Opens a file like a text editor.
    • /etc/apt/sources.list: It’s the configuration file.

    shows the file content of sources.list file.Here in the sources.list file, notice the lines start with ‘deb’ and ‘deb-src’. These lines specify the repositories you are currently using as marked in the picture.

  2. Now choose a new mirror from the Ubuntu Mirror list (https://launchpad.net/ubuntu/+archievemirrors). Pick a mirror that is compatible with your geographical location and replace the URL with the existing URL in the source.list file.Shows the newly added mirror repository in the file.

In my case, I’ve replaced the previous mirrors with the marked Mirror URLs. After modification, save the file and exit by pressing CTRL+O and CTRL+Z.

Error 5: Inadequacy of Disk Space

If your system is running out of disk space, it can prevent apt-get from updating which causes in ‘Failed to Fetch’ error.

Solution: Free up Disk space

To check the system’s disk space, follow as below:

  1. Open the Ubuntu terminal.
  2. Run the following command to get enlisted data of used and unused space of disk:
    df -h
    EXPLANATION
    • df: This command displays disk space information.
    • -h: The option ‘h’ stands for ‘human-readbale’. Due to using option ‘-h’ in the command, ‘df’ displays the sizes in an understandable format with kilobytes(K), megabytes(M), and gigabytes(G) units.

    Shows the storage information of the system.Here, you can check the files that are occupying your disk space including their size, used space, and available space. The information also includes the ‘Mounted on’ column which indicates the mount point or directory where the system file is attached in the file system hierarchy.

If your system’s disk space is full, then free up some space according to your needs. To clean up some unnecessary occupied spaces run the following commands:

sudo apt-get autoremove
sudo apt-get autoclean

Error 6: GPG Errors

When you execute the sudo apt update command and come across the ‘GPG error’, it usually signals a problem with the GPG (GNU Privacy Guard) key responsible for confirming the authenticity of software packages within your package manager’s repository. This issue can impede your ability to update your package lists and install or upgrade software packages.

Solution: Find and Resolve Malfunction in the Configuration File

While trying to update my packages, the GPG error hinders the operation as you can notice from the picture. The error message includes the repository and mentions that the public key is not available. This problem can occur for multiple reasons. Shows GPG error while running the sudo apt-get update command.

To resolve the GPG errors to fix the sudo apt-get update not working issue follow the steps below:

  1. Open a terminal on Ubuntu.
  2. Run the following command to open the file /etc/apt/sources.list:
    sudo nano /etc/apt/sources.list
    EXPLANATION
    • sudo: Provides the root privilege to perform the administrative command.
    • nano: Opens files in CLI and allows you to edit the file like a text editor including multiple features.
    • /etc/apt/sources.list: contains a list of software repositories or sources from which the apt package manager retrieves and installs software packages.

    Opens the sources.list file.

  3. Enter the user password and the file will be opened.Shows the texts of the sources.list file. As the file opened, I searched for the line ‘deb https://pkg.jenkins.io/debian binary/,’ which configures an APT repository for Jenkins. Jenkins is a widely used automation server that plays a crucial role in building, deploying, and automating software projects.
  4. Remove the marked line or use a hash ‘#’ icon in front of the line to comment out the line.

  5. Now, run the command sudo apt-get update again and update your system packages:

    sudo apt-get update

    Updates the packages properly after resolving the error.Now, here you can see the result of the sudo apt-get update command as you’ve anticipated.

Error 7: Could not Get Lock “/var/lib/apt/lists/lock” Error

This error occurs when another instance of ‘apt’ or package management tool is running. In this situation, if you run the command ‘sudo apt-get update’  command, you’ll get an error like below.Shows could not get lock error while running apt-get update command.

Solution: Check & Terminate Any Other APT Processes

You can check for any apt processes running or not and then if it’s necessary, you can terminate the process to run the sudo apt-get update command.

To resolve the sudo apt-get update not working error, check and terminate if any other “apt” processes are running. Here is how:

  1. Open the terminal in Ubuntu.
  2. Now, identify and terminate processes running on your system using the following command:
    sudo fuser -vki  /var/lib/apt/lists/lock
    EXPLANATION
    • sudo: Provides the root privilege.
    • fuser: It’s a command used to identify which processes are currently using a particular file or resource.
    • -v: This option stands for ‘verbose’ and instructs the command to display more information about the processes using the file.
    • -k: This option tells the ‘fuser’ to send a signal to the processes using the file to kill them.
    • /var/lib/apt/lists/lock: This is the absolute path to the lock file that is used by APT.

    This command terminates the currently running process.Here you can see that the process running by APT is detected. If you press ‘Y’  the running process will be terminated as below.Shows the result of killing the running process.

    Now, wait for a few moments to ensure that the lock is released.

If you are sure that there are no other processes holding the lock, then it’s possible that a stale lock file is causing the issue. Then run the following command to remove the lock:

sudo rm /var/lib/apt/lists/lock
EXPLANATION
  • sudo: This is used to run another command with superuser privilege.
  • rm: This is the remove command that deletes files and repositories.
  • /var/lib/apt/lists/lock: This is the full path to the lock that you want to remove.

Fix the Slow APT-GET Update Issue

It’s not so rare to face a slow downloading speed for packages while running the ‘‘sudo apt-get update’ command. This issue can occur in case your connected server is really busy. Besides, slow speed happens due to mirror issues, name server issues, and repositories issues. To resolve the situation, you can check the repositories in your /etc/apt/sources.list file, or select a DNS server with fast speed, and clean the apt-get cache.

Solution 1: Transport HTTP Mirror to HTTPS Mirror in sources.list File

You can transport http to https to enhance the security and integrity of data. For that, you have to run the following command to install apt-transport-https package:

sudo apt install apt-transport-https

Installs the https trasnport.After installing the ‘apt-transport-https’ package, you have to edit resources in the sources.list file. To do that run the following command:

sudo nano /etc/apt/sources.list

Shows the content of sources.list file.Here, you can see HTTP which you have to change to HTTPS. Everytime you encounter an HTTP, switch that to HTTPS  in the sources.list file. Then save and exit from the file by pressing CTRL+O & CTRL+X.All the HTTP are changes to HTTPS.After changing all the HTTP to HTTPS, run the following commands respectively:

sudo apt update
sudo apt upgrade -y

Update and Upgrades the packages fast.From the above image, you can see that the commands are working perfectly without any slow-down issues.

Solution 2: Change HTTP to Repo in sources.list File

To change HTTP to repo in the sources.list file, you have to install a utility called netselect. Run the following command to install netselect:

wget http://ftp.au.debian.org/debian/pool/main/n/netselect/netselect_0.3.ds1-28+b1_amd64.deb
EXPLANATION
  • wget: This is a command line utility for downloading files from the internet.
  • http://ftp.au.debian.org/debian/pool/main/n/netselect/netselect_0.3.ds1-28+b1_amd64.deb: This is the URL of netselect package file that I want to download.

Installs netselects.Now, using the command sudo dpkg -i netselect_0.3.ds1-28+b1_amd64.deb, install a Debian package with the filename netselect_0.3.ds1-28+b1_amd64.deb using the dpkg tool.

sudo dpkg -i netselect_0.3.ds1-28+b1_amd64.deb

installs a specific debian package.Then use the command netselect -s 20 -t 40 $(wget -qO – http://mirrors.ubuntu.com/mirrors.txt) to evaluate the performance of the top 20 source hosts listed in the mirror source list.

netselect -s 20 -t 40 $(wget -qO - http://mirrors.ubuntu.com/mirrors.txt)

Enlists 20 source hosts.After that, from the enlisted mirror source list, you can replace the existing server domain (archive.ubuntu.com)with the first enlisted mirror server mirror.limda.net. Do this for all the entries of sources.list file and save the file using the following command:

vi /etc/apt/sources.list

Replace the server in sources.list file from the 20 listed source hosts.At last run the following commands separately to update the repository source:

sudo apt update
sudo apt upgrade -y

Updates and Upgrades packages which solves the apt-get update not working problem.You can see here, the commands are working perfectly without any slow-down issues.

Conclusion

In summary, ‘sudo apt-get update’ is a crucial command for maintaining the stability, security, and optimal performance of your Debian-based Linux system. By regularly updating your package information, you ensure an up-to-date operating system environment. However, occasionally, unexpected issues may arise during the update process. Fortunately, this article has provided the solutions to the multiple errors a user may face while running the sudo apt-get update command. Hope this information has been helpful in troubleshooting and improving your Linux system’s overall health.

People May Ask

How do I fix update error in Ubuntu?

To fix the update error in Ubuntu:

  1. Check internet connectivity.
  2. Check Ubuntu software sources: Check the ‘/etc/apt/sources.list’ file or any incorrect entries to find any misconfigured software sources.
  3. Clear APT cache: Use the sudo apt-get clean command to clear the apt cache.
  4. Fix Dependencies: In case of any broken dependencies, use the sudo apt-get install -f command.
  5. Update and Upgrade Package lists.
  6. Check for error messages.
  7. Reboot the System.

How do I update my apt-get application?

To update the apt-get application, you can do it:

  1. Open the terminal and Update the package list using the sudo apt-get update command.
  2. Then, upgrade installed packages using the sudo apt-get upgrade command.

The commands will upgrade all the installed packages to their latest versions.

How do I update my apt version?

To update the apt version, first, ensure your current distro version is up to date by running the sudo apt-get update and sudo apt-get upgrade commands. Then, use the command sudo do-release-upgrade to check for and upgrade to the latest Ubuntu version.

How to force update Linux?

To force an update on Linux, you can run the update-manager -d command in the terminal to upgrade to the development release. The -d option is used to upgrade to the latest development release.

What does “apt-get clean” do?

The apt-get clean command removes all the downloaded package files (.deb) from the local cache (/var/cache/apt/archives). This frees up disk space by deleting unnecessary files.

What is ‘apt-get’?

The ‘apt-get’ (Advanced Package Tool – GET) is a command line tool used for package management in Debian-based Linux distributions. Its common functionality includes installing, removing, and updating packages.

What does apt-get upgrade do?

The ‘apt-get upgrade’ command mainly downloads and installs the latest versions of all currently installed packages. It replaces your system with the most up-to-date software by replacing the older package version with the newer one.

When should I run apt upgrade?

You should run ‘apt upgrade’ periodically to keep your system up-to-date with security patches and bug fixes. 

How do I clear my apt update cache?

To clear the apt cache, use the apt-get clean command in the terminal. But first, update the package list using the “apt-get update” command to make sure you have the most recent version of the package lists. Then, clean the cache. The “clean” command clears out the local repository of the retrieved package files. It removes everything but the lock file from ‘/var/cache/apt/archieves/’ and ‘/var/cache/apt/archives/potential/’. If you want to remove packages that are no longer required, use sudo apt-get autoremove command after cleaning the cache.

Related Articles


<< Go Back to Update Packages in Linux | Package Management in LinuxLearn Linux Basics

5/5 - (1 vote)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
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

2 thoughts on “[Fixed] “sudo apt-get update” Not Working in Ubuntu”

  1. thank you so much !
    For those who don’t find the Application & update.
    You need to install it with “sudo apt-get install ubuntu-desktop”
    and follow his step by unchecking every checked button.

    Reply
  2. Thanks for the detailed troubleshooting steps! I was stuck with the “sudo apt-get update” error for hours. Your fix worked like a charm—greatly appreciated!

    Reply

Leave a Comment