APT GET on Ubuntu

APT is a command line tool on Ubuntu. It is one of the most used and extremely powerful command line tools on Ubuntu. APT can be used to install new software packages, update packages already installed on your system, or even upgrade. This command-line tool is by far one of the first things any Linux novice learns. APT can be divided into APT-GET, APT-CACHE and APT-CONFIG. In this tutorial we will explore the different ways we can use APT-GET.

Apt-get source and Apt-get build-dep

Apt-get source

When dealing with open source packages or source code, programmers usually want to study the source code and/or debug the source code. This is where Source comes in. Source is used to grab the source package.

For this to work, point the deb-src entry in /etc/apt/sources.list to unstable (it should also be uncommented). Perform an update once the sources.list file has changed.

CD /Etc/suitable

nano Sources.List

Then uncomment the deb-src lines.

Then perform an update:

sudo apt get update

Download the source package:

CD ~

CD Downloads

mkdir imagemagick_source

CD imagemagick_source

sudo apt-get source image magic

Untitled15

The following is in the imagemagick_source folder:

Untitled16

sudo apt-get build-dep <package>

The latter is used to install all of the dependencies for a given package that will allow it to be built. In other words, dependencies are libraries/programs required to compile the package. And the latter will get the dependencies for you.

sudo Install apt get <package>

sudo Install apt get <package>

This is the command that most people are forced to use and is therefore the most well known and used. It will download and install any package of your choice. So let’s see what it does:

Untitled6

In this case I decided to install a package that I already have on my system. However, what you need to pay attention to are the first two lines.

Read package lists… Done” – went through the software repository and checked all available packages.

Create dependency tree‘ – this is where apt-get builds the other packages needed to run the desired package.

Untitled7

APT will fetch all requests and install them as well. /etc/apt/sources.list is used to locate the packages. To install a specific version of a package, you can write:

sudo Install apt get <package names>=<package version>

On the other hand, if you just wanted to download the package but not install it, you can do that by adding the d switch. The latter downloads the file and places it in /var/cache/apt/archives.

sudo apt-get -i.e To install <package>

Untitled8

You can also simulate an installation with the s switch (-s, -simulate, -just-print, -dry-run, -recon, -no-act)

sudo apt-get -s installl <package>

The latter does not alter the system in any way, shape or form, but rather simulates an installation. When a non-root user simulates an installation, it may look garbled due to lack of access to certain configurations.

The next thing we’ll look at is the fix-broken (-f, -fix-broken):

sudo apt-get -f To install <package>

In this case, an attempt is made to repair broken dependencies.

sudo apt-get automatic cleaning/clean

sudo apt-clean

This command – clean – is used to clean the local repository of packages. It removes everything from /var/cache/apt/archives, which basically frees up some disk space on the system.

sudo apt-get autoclean

Autoclean, on the other hand, is used to remove useless files.

Suppose I download (and only download) VLC with the command. sudo apt-get -d install vlc. This is what /var/cache/apt/archives looks like:

Untitled9

Now let’s use Autoclean:

sudo apt-get autoclean

Untitled10

And now let’s clean up:

Untitled11

By now it is assumed that you have figured out what clean does and what doesn’t.

sudo apt-get –clean Extinguish <package>

sudo apt-get –clean Extinguish <package>

To remove a package with APT you can either use purge or remove or both here. Remove is used to remove the package but NOT the configuration files. Purge also removes all configuration files.

sudo apt-get autoremove

sudo apt-get autoremove <package>

Whenever you install a specific package, all of its dependencies are also installed automatically. On the other hand, if you remove the package, the package is removed but the dependencies remain. This is where apt-get autoremove comes into play. Autoremove not only removes the installed package, but also the installed dependencies.

Untitled17

sudo apt get update

sudo apt get update

As the term suggests, this command is used to update. What is updated now and what does the command do? In this case, the /etc/apt/sources.list file is consulted and the database of packages available to the user is updated. If the sources.list file ever changes, be sure to run this command.

Untitled

So here, in the previous image, I ran the update command and we can see that it ejects a few lines. These lines say “Hit”, “Get” or “Ign”.

Match: No changes in package version

Get: New version is available and APT will get it for you

Ign: Ignore the packet

The APT update will not download and install all newly available packages. However, you can type the following to see which ones have a newly available version:

matching list – upgradable

Untitled2

As you can see, this shows the current version (on your system) you have and the new version available.

sudo apt-get upgrade

sudo apt-get upgrade

The next command that is similar to the update command is the upgrade command. The latter command (upgrade) is used to upgrade or install newer versions of all the various packages that are already installed on the system. It fetches the latest versions from the sources located in the etc/apt/sources.list file. Packages already installed on a system are NEVER removed and new packages not currently installed are never installed. However, the “upgrade” applies to ALL packages currently installed on the system. If a package cannot be upgraded without changing the status of another package, it remains UN-UPGRADED. Typically, the upgrade command is preceded by the update command. This is to ensure that APT knows that there are indeed new packages out there.

sudo apt-get dist-upgrade

sudo apt-get dist-upgrade

This special command is used to update the system to a new version. In this case, some of the packages can be removed. The difference between the upgrade and dist-upgrade commands is that dist-upgrade removes specific packages. But there is no package removal for the upgrade.

sudo apt-get download

sudo apt-get download <package>

This is similar to -d install. Apt-get -d install downloads the file to /var/cache/apt/archives while apt-get download downloads the deb file to the current working directory. Apt-get download downloads the deb file but not the dependencies. Also, apt-get download doesn’t install the package.

sudo apt get check

sudo apt get check <package>

Sudo apt-get check is used to update the package cache and check for broken dependencies.

For more information and more options please enter:

man apt-get

Conclusion

The APT GET commands are very powerful and yet very simple. In this tutorial, we learned how to use the APT GET commands: source, build-dep, install, clean, autoclean, purge, remove, autoremove, update, upgrade, dist-upgrade, download and check were covered in this tutorial .

Related Posts