You get a bonus - 1 coin for daily activity. Now you have 1 coin

Updating an Ubuntu Server with sudo apt update, sudo apt upgrade

Lecture



Fixing problems when installing and updating programs on the server

Foreword

Sometimes, when working with package managers, you run into a problem with unresolved package dependencies. This article looks at ways to solve this problem.

A typical scenario after a long time without updates looks like this

  • the update will happen in several stages at once, jumping 2 versions at a time (from 16 to 18, and so on)
  • there will be a bunch of problems — during the update itself (some repos no longer exist), when the server starts, and on every reboot.
  • after the update and fixing the previous problems —
  • newer PHP versions are forced on you. The old ones won't install, and if they do install, they're broken, which means sites don't work on the old versions... so either you update the sites — the frameworks — or you go back to reinstalling old PHP versions again
  • —so what's the point of the whole update?)))!
  • the server will be unreachable to the world several times, so you need some kind of backup
  • so, the update brings its own set of problems((, but they can be solved too, it just takes a while

Updating an Ubuntu Server with sudo apt update, sudo apt upgrade

let's take a closer look at the possible problems when updating a Linux server and how to solve them.

All operations are performed in the terminal.
Make sure no package manager is running. This could be: apt-get, aptitude, Synaptic, KPackageKit, Ubuntu Software Center, etc.

Using APT-GET

The error usually looks like this:

E: Unable to satisfy dependencies. Try running 'apt-get -f install' without specifying a package name, (or find another solution).

Clear the package cache:

sudo apt-get clean

Remove orphaned packages:

sudo apt-get autoremove

Update the package list:

sudo apt-get update

Fix the dependencies:

sudo apt-get -f install

Usually that's enough.

If you're confused about dependencies, an intelligent system update can help:

sudo apt-get dist-upgrade

If the installation was interrupted, you should reinstall the package

sudo apt-get install --reinstall package_name

If the repository is unavailable, fix:

  • /etc/apt/sources.list - the main list of repositories
  • /etc/apt/sources.list.d - the directory for third-party repositories

If it's impossible to remove/reinstall a package, fix:

  • /var/lib/dpkg/status - the list of installed packages
  • /var/lib/dpkg/available - the list of packages available for download
Updating an Ubuntu Server with sudo apt update, sudo apt upgrade

example of the problem

to solve the problem with lost packages, you need to edit the file
for example
instead of
http://ubuntu.mirror.serverloft.eu/
replace with
http://security.ubuntu.com/ubuntu/
or check the local DNS resolver and change it from the provider's DNS to, for example, Google DNS 8.8.8.8
deb http://security.ubuntu.com/ubuntu xenial main universe multiverse restricted
deb-src http://security.ubuntu.com/ubuntu xenial main universe multiverse restricted
# updates
deb http://security.ubuntu.com/ubuntu xenial-updates main universe multiverse restricted
deb-src http://security.ubuntu.com/ubuntu xenial-updates main universe multiverse restricted
# security updates
deb http://security.ubuntu.com/ubuntu xenial-security main universe multiverse restricted
deb-src http://security.ubuntu.com/ubuntu xenial-security main universe multiverse restricted

instead of

deb http://security.ubuntu.com/ubuntu xenial main universe multiverse restricted
deb-src http://security.ubuntu.com/ubuntu xenial main universe multiverse restricted

# updates

deb http://security.ubuntu.com/ubuntu xenial-updates main universe multiverse restricted
deb-src http://security.ubuntu.com/ubuntu xenial-updates main universe multiverse restricted

# security updates

deb http://security.ubuntu.com/ubuntu xenial-security main universe multiverse restricted
deb-src http://security.ubuntu.com/ubuntu xenial-security main universe multiverse restricted

Updating an Ubuntu Server with sudo apt update, sudo apt upgrade

  • apt-get update downloads package lists from the repositories and «refreshes» them to get information about the latest versions of packages and their dependencies. This is done for all repositories and PPAs.

    Used to re-synchronize the package index files from their sources. The indexes of available packages are fetched from the locations specified in /etc/apt/sources.list(5). You should always run an update before upgrading or doing a dist-upgrade.

  • apt-get upgradewill fetch new versions of packages already installed on the machine, provided APT has learned about these new versions in the order given by apt-get update.

sudo apt update

Updating an Ubuntu Server with sudo apt update, sudo apt upgrade

apt list --upgradable

Listing... Done
libpython2.7/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]
libpython2.7-dev/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]
libpython2.7-minimal/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]
libpython2.7-stdlib/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]
python2.7/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]
python2.7-dev/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]
python2.7-minimal/xenial-updates,xenial-security 2.7.12-1ubuntu0~16.04.14 amd64 [upgradable from: 2.7.12-1ubuntu0~16.04.13]

sudo apt upgrade

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib python2.7 python2.7-dev python2.7-minimal
7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.9 MB of archives.
After this operation, 18.4 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Err:1 http://security.ubuntu.com/ubuntu xenial-security/main amd64 python2.7-dev amd64 2.7.12-1ubuntu0~16.04.14
  404  Not Found [IP: 91.189.88.152 80]
Ign:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64  
  404  Not Found [IP: 91.189.88.152 80]
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libpython2.7-dev amd64 2.7.12-1ubuntu0~16.04.14
 

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/libpython2.7-stdlib_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7-minimal_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/libpython2.7-minimal_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

sudo apt upgrade --fix-missing

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib python2.7 python2.7-dev python2.7-minimal
7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.9 MB of archives.
After this operation, 18.4 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Err:1 http://security.ubuntu.com/ubuntu xenial-security/main amd64 python2.7-dev amd64 2.7.12-1ubuntu0~16.04.14
  
Err:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libpython2.7-stdlib amd64 2.7.12-1ubuntu0~16.04.14
  404  Not Found [IP: 91.189.88.152 80]
Err:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 python2.7-minimal amd64 2.7.12-1ubuntu0~16.04.14
  404  Not Found [IP: 91.189.88.152 80]
Err:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libpython2.7-minimal amd64 2.7.12-1ubuntu0~16.04.14
  404  Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7-dev_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

 

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/libpython2.7-stdlib_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7-minimal_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/libpython2.7-minimal_2.7.12-1ubuntu0~16.04.14_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

Updating the System and Release

To find out which Linux distribution and version is in use, try running the following command in the console of the running system:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial

The recommended way to update an installed Server Edition is to use the do-release-upgrade utility. Being part of the update-manager-core package, it has no graphical interface and is installed by default.

Systems based on the Debian distribution can also be updated using the apt-get dist-upgrade command. However, using do-release-upgrade is preferable, since it allows you to track changes in system configurations when moving from one release to another.

To update to a new release, enter the following command in the terminal:

do-release-upgrade

There is also an option to upgrade using do-release-upgrade to the development version of Ubuntu. To do this, add the -d option to the command:

do-release-upgrade -d

See also

[[b5894]]

See also

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system