HOW TO UPDATE ALL IN UBUNTU

<-Back | hereinafter>

The command apt-get - the console is a powerful tool that works with an improved package tools (APT) Ubuntu, performing such functions as installation of new software packages, upgrade packages available, update the package list index, and even update all Ubuntu systems.

Being a simple console tool, apt-get has a number of advantages over other package management tools available in Ubuntu for server administrators. Some of these advantages include easy using simple terminal connections (SSH) and the ability to use scenarios of system administrators, which may be automated using cron scheduling utility.

Some examples of popular uses tools apt-get:

  • Install a Package: Installation of packages using the apt-get tool is very simple. For example, to install the network scanner nmap, type the following:

sudo apt-get install nmap

  • Removal packet: Remove a package (or packages) the same primitive. To remove a package installed in the previous example, type the following:

sudo apt-get remove nmap

Several packages: You can specify multiple packages to install or uninstall, separated by spaces.

Furthermore, the addition -purge options to apt-get remove will remove also the configuration files. It may be desirable or undesirable, so use with caution.

  • Update the Package Index: the APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file and /etc/apt/sources.list.d directory. To update the local package index with the latest changes to the repositories, type the following:

sudo apt-get update

  • Upgrade Packages: Over time, updated versions installed on your computer packages may be available in the repositories (for example security updates). To update your system, first update your package index as outlined above, and then run:

sudo apt-get upgrade

For information on upgrading to a new Ubuntu release, see Upgrade

action commands apt-get, such as installing and removing packages are stored in a log file /var/log/dpkg.log.

For further information on the use of APT, read Debian APT User Manual or type a comprehensive guide:

apt-get help

<-Back | hereinafter>

APT-GET UPDATE

In a nutshell, apt-get update doesn’t actually install new versions of software. Instead, it updates the package lists for upgrades for packages that need upgrading, as well as new packages that have just come to the repositories.

  • apt-get update downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs. From http://linux.die.net/man/8/apt-get:

    Used to re-synchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list(5). An update should always be performed before an upgrade or dist-upgrade.

  • apt-get upgrade will fetch new versions of packages existing on the machine if APT knows about these new versions by way of apt-get update.

    From http://linux.die.net/man/8/apt-get:

    Used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list(5). Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, nor are packages that are not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. [Emphasis mine] An update must be performed first so that apt-get knows that new versions of packages are available.

  • apt-get dist-upgrade will do the same job which is done by apt-get upgrade, plus it will also intelligently handle the dependencies, so it might remove obsolete packages or add new ones. See here: What is "dist-upgrade" and why does it upgrade more than "upgrade"?

    From http://linux.die.net/man/8/apt-get:

    In addition to performing the function of upgrade, this option also intelligently handles changing dependencies with new versions of packages; apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones, if necessary. The /etc/apt/sources.list(5) file contains a list of locations from which to retrieve desired package files. See also apt_preferences(5) for a mechanism for over-riding the general settings for individual packages.

You can combine commands with && as follows:

sudo apt-get update && sudo apt-get install foo bar baz foo-dev foo-dbg

or to get newest versions possible as per version requirements of dependencies:

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

You need sudo both times, but since sudo by default doesn’t prompt you within 5 or so minutes since the last sudo operation, you will be prompted for your password only once (or not at all).

SUDO APT-GET INSTALL

Complete beginner's guide to use apt-get commands in Linux

Brief: This beginner’s guide shows you what you can do with apt-get commands in Linux, how to use it to find new packages, install and upgrade new packages and clean your system.

If you have started using Ubuntu or any other Ubuntu based Linux distribution such as Linux Mint, elementary OS etc, you must have come across apt-get command by now.

In fact, first in the list of things to do after installing Ubuntu is to use apt-get update and apt-get upgrade. Now, you might be aware of a few commands and their usage but perhaps you might not be aware of other apt-get commands and their usage.

In this guide for beginners, I am going to explain various of apt-get commands with examples so that you can use them as an expert Linux user.

Exclusive bonus: Download apt-get command cheatsheet for future reference. You can print it or save it for offline viewing.

What is apt-get?

Ubuntu is derived from Debian Linux. And Debian uses dpkg packaging system. A packaging system is a way to provide programs and applications for installation. This way, you don’t have to build a program from the source code.

APT (Advanced Package Tool) is the command line tool to interact with this packaging system. There is already dpkg commands to manage it. But apt is more friendly way to handle packaging. You can use it to find and install new packages, upgrade packages, clean the packages etc.

There are two main tool around it: apt-get and apt-cache. apt-get is for installing, upgrading and cleaning packages while apt-cache is used for finding new packages. We’ll see all these commands with examples later in this guide.

I am using Linux Mint 18 in this tutorial but you can use any other Ubuntu based Linux distributions such as elementary OS, Linux Lite etc.

Using apt-get commands

Let’s first start with apt-get commands. You just cannot escape this command. It’s better to have an understanding of these commands so that you can handle your Linux system in a slightly better way.

Update package database with apt-get

apt-get basically works on a database of available packages. If you don’t update this database, the system won’t know if there are newer packages available or not. In fact, this is the first command you need to run in any Linux system after a fresh install.

Updating the package database requires super user privileges so you’ll need to use sudo.

sudo apt-get update

When you run this command, you’ll see the information being retrieved from various servers.

apt-get update command

You’ll see three types of lines here, hit, get and ign. Let me explain that to you:

  • hit: there is no change in package version
  • ign: the package is being ignored. There could be various reasons for that. Either the package is way too recent that it doesn’t even bother to check or there was an error in retrieving the file but error was trivial and thus it is being ignored. This is not an error. There is no need to be worried.
  • get: There is a new version available. It will download the information (not the package itself). You can see that there are download information with the ‘get’ line in the screenshot above.

Upgrade installed packages with apt-get

Once you have updated the package database, you can upgrade the installed packages. The most convenient way is to upgrade all the packages that have updates available. You can use the command below for this purpose:

sudo apt-get upgrade

apt-get upgrade command

To upgrade only a specific program, use the command below:

sudo apt-get upgrade 

There is another way to provide a complete upgrade by using the command below:

sudo apt-get dist-upgrade

This actually looks for the dependencies with the newer version and tries to install it. But you should avoid using it. I’ll explain it in the next section.

Difference between upgrade and dist-upgrade

The command apt-get upgrade is very obedient. It never tries to remove any packages or tries to install a new package on its own.

The command apt-get dist-upgrade, on the other hand, is proactive. It looks for dependencies with the newer version of the package being installed and it tries to install a new package or remove an existing one on its own.

It sounds like dist-upgrade is more powerful and intelligent, isn’t it? But there is a risk with it.

See, it has a ‘smart’ conflict resolution system. With that in place, it will attempt to upgrade the most important packages on the expense of the less important ones. This may lead to the removal of some packages which you might not want. This is the main reason why dist-upgrade should be avoided on production machines.

What is the difference between apt-get update and apt-get upgrade?

This is a very common confusion. You are not the only one to be confused by the term update and upgrade.

Though it sounds like when you do an apt-get update, it will update the packages. But that’s not true. apt-get update only updates the database of the packages. For example, if you have XYX package version 1.3 installed, after apt-get update, the database will be aware that a newer version 1.4 is available.

When you do an apt-get upgrade after apt-get update, it upgrades (or updates, whichever term you prefer) the installed packages to the newer version.

This is the reason why the fastest and the most convenient way to update your system is to use this command:

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

Using apt-cache commands to search for packages

I’ll be honest with you. This is not my preferred way of searching for packages. But this comes pretty handy when you are looking for some specific lib.

All you need to do is to use the following command. You don’t even need sudo here.

apt-cache search 

search packages with apt in linux command line

You don’t need to know the exact name of the package. It searches in package name and their short description and shows result based on that.

If you just want to search the packages with specific package names, you can use the command below:

apt-cache pkgnames 

This gives you the list of all the packages starting with your search term.

available package details in Linux command line

Once you know the exact package name, you can get more information about it such as version, dependencies etc by using the command below:

apt-cache showpkg 

apt-get command install packages

How to install new packages with apt-get

If you know the name of the package, you can easily install it using the command below:

sudo apt-get install 

Just replace the with your desired package. Suppose I want to install Pinta image editor, all I need to do is to use the command below:

sudo apt-get install pinta

The good thing about this command is that it has auto-completion. So if you are not sure about the exact package name, you can type a few letters and press tab and it will suggest all the packages available with those letters. For example:

install packages in command line linux

How to install multiple packages

You are not restricted to install just one package at a time. You can install several packages at a time by providing their names:

sudo apt-get install   

installing packages in Linux

What if you run install on an already installed package?

Suppose you have already a package installed but you used the install command for the already installed package. This will actually look into the database and if a newer version is found, it will upgrade the installed package to the newer one. So no harm done by using this command unless you don’t want it to be upgraded.

How to install packages without upgrading

Suppose for some reason you want to install a package but don’t want to upgrade it if it is already installed. Sounds weird, but you may have your reasons to do that.

For that case, you can use the sub –no-upgrade in the following manner:

sudo apt-get install  --no-upgrade

no upgrade package Linux

How to only upgrade packages, not install it

In case you only want to upgrade a package but don’t want to install it (if it’s not already installed), you can do that with the following command:

sudo apt-get install  --only-upgrade

only upgrade packages with apt-get Linux

How to install a specific version of an application

By default, the latest version available in the repository will be installed for any application. But for some reasons, if you don’t want to install the latest version, you can specify the version number (you would need to know the exact version number that you want to install).

All you need to do is to add =version with the name of the package.

sudo apt-get install =

How to remove installed packages with apt-get

It’s not that you can only install packages with apt-get. You can also remove packages with it. All you need to do is to use the command in this manner:

sudo apt-get remove 

Auto-completion works here as well. So you just start typing package name and press tab and it will suggest all the installed packages starting with those letters.

Another way of uninstalling packages is to use purge. The command is used in the following manner:

sudo apt-get purge 

What is the difference between apt-get remove and apt-get purge?

  • apt-get remove just removes the binaries of a package. It doesn’t touch the configuration files
  • apt-get purge removes everything related to a package including the configuration files

So if you have ‘remove’ a particular software and install it again, your system will have the same configuration files. Of course, you will be asked to override the existing configuration files when you install it again.

Purge is particularly useful when you have messed up with the configuration of a program. You want to completely erase its traces from the system and perhaps start afresh.

Most of the time, simple remove is more than enough for uninstalling a package.

How to clean your system with apt-get

Oh yes! You can also clean your system with apt-get and free up some disk space.

You can use the command below to clean the local repository of retrieved package files:

sudo apt-get clean

Another way is to use autoclean. Unlike the above clean command, autoclean only removes those retrieved package files that have a newer version now and they won’t be used anymore.

sudo apt-get autoclean

Another way to free up disk space is to use autoremove. It removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If the package is removed, these automatically installed packages are useless in the system. This command removes such packages.

sudo apt-get autoremove

This is command-line way of cleaning Linux system. If you prefer GUI, here are some CCleaner alternatives for Linux which you can use on Ubuntu and Ubuntu based Linux distributions.

Your input

There is more to apt-get but this much would give you a pretty good start. You can always look up to the man pages to get more information.

How do you like this guide to apt-get commands in Linux? Was it helpful to you and clear enough to understand? Your feedback will help in creating more such guides in near future.

Read in other languages

 BelorussianEnglish Deutsch Spanish French Italian Portuguese Turkish Arab Ukrainian Swedish Hungarian Bulgarian Estonian Chinese (Simplified) Vietnamese Romanian Thai Slovenian Slovak Serbian Malay Norwegian Latvian Lithuanian Korean Japanese Indonesian Hindi Hebrew Finnish Greek Dutch Czech Danish Croatian Chinese (Traditional) Philippine Urdu Azeybardzhansky ArmenianPolish Bengal Georgian Kazakh Catalan Mongolski Russian Tadzhitsky Tamilʹskij telugu Uzbetsky

Read more:   How to download the program WORD EXEL

Add a comment

Your e-mail will not be published. Required fields are marked *