Apt and Apt-Get Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/apt-and-apt-get-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

Distributions like Ubuntu, Debian uses APT as default online package manager. APT works with dpkg together where apt resolves dependencies and download packages from internet, network share etc. and dpkg installs, configure them. In this tutorial we will look how to use apt efficiently APT packages extensions are .deb which is actually dpkg packages. There is GUI application manager synaptic which have base features of the APT. Here is simple package name the information provided by package name.

  • Yaketty is the packages original name which is given by upstream provider. Some times package names can be change and different from upstream provider. But this situation is very rare.
  • 4.9.0 is version which is provided by the upstream developer.
  • -2 is version added by package maintaner in  Ubuntu repository. Some times distribution realted updates may needed different from original program.
  • amd64 is system architecture for this package which means it supports 64 bit.

Update Packages

Updating packages are done with two stages. First we will update repository information. Repository is place where packages are hold in the http or ftp server. Repository provides packages and metadata or information about packages. This information will get and then required packages will updates.

As we can see from screen shot we get information about packages from tr.archive.ubuntu.com and updated our local information base.

Now we will upgrade our packages.

We can use following command to make upgrade job more automatic

With this command upgrade related question will be automatically answered.

To make things simple we can combine these two command in to single line like below.

Yes We Can

While upgrading we can see questions like Do you want to continue? [Y/n] Y We can automatically answer all questions with yes like below.

Search Packages

Searching packages are easy. We will just provide the term or package name we want to search

We can see that there are some packages in the list but  there is no string in the line like tmux. Searching is done in the package details too where we look next. We can search as term which is like google free text search. We get more results .

LEARN MORE  How To Convert Disk Formats For Qemu, Vmware

Package Info

We may want to get package details information about installed-size, architecture, dependencies, version, file name, description,mainainer,  etc.

Install Packages

Installing packages is easy as other operations wejujst provide our package name to the apt-get install command like below.

We can provide -y option to prevent question and directly install package. The prosition of the -y option is not important.

To select more than one package with globing asterisk * can be used. This will select all package those starts with xfce4-

We can also install multiple package in the same command by separating them spaces .

Remove Packages

Removing packages is similar to installing them. We provide the name of the package to the apt-get remove command.

Remove Packages

Remove Packages

Remove Packages

Remove Packages

Remove by providing yes option with -y

Remove Package With Configuration

Normally removing package will uninstall the package binary files and documentation. Configuration files are do not removed for future installation. If we want to remove configuration files too we need to provide –purge option.

Remove Package With Configuration

Remove Package With Configuration

Remove Clean Cache

Cache is intermediate storage used APT where downloaded packages are hold. After some time with new versions of packages we can clean this cache like below.

Remove Clean Cache

Remove Clean Cache

Check Dependencies

Dependency is the requirement to install other related packages to install a package. For example to install Gnome Desktop, Gnome Terminal must be installed and here Gnome Terminal is a dependency for Gnome Desktop. To get dependencies showpkg sub-command will be used.

Check Dependencies

Check Dependencies

Here we check dependencies of the tmux package. We can see that there is two part of dependencies.

  • Dependencies part provides required packages to install tmux.
  • Reverse Dependencies provides which packages needs the tmux package.
LEARN MORE  Linux hosts.allow and hosts.deny To Control Network Access

Get Statistics Of Cache

Cache is used to store information about packages. There is command named stat which is used to get overll statistics information.

Get Statistics Of Cache

Get Statistics Of Cache

Stats sub-commands provides information like;

  • Total package names 
  • Virtual packages count
  • Missing package count
  • Space used for cache

Update System Packages

Installed packages can be updated easily. /etc/apt/sources.list provides information about repositories those provides updates for packages. Update operation will get most recent information about packages from provided repositories and saved to the cache.

Update System Packages

Update System Packages

Upgrade Specific Package

Upgrade operation is generally done in total mode where all package are updated.. But there are some times where only some of the packages should be updated like below.

Upgrade Specific Package

Upgrade Specific Package

Install Multiple Packages

Install multiple package can be done with simple separating package names with spaces like below. For example to install tmux and ksh in a single shot apt command use following example.

Install Multiple Packages

Install Multiple Packages

Install Using Wildcards

Another way to install multiple packages is using wildcard. Wildcard is asterisk * which means that anything goes well for the asterisk. To install gnome packages like gnome-specimen, gnome-twich, gnome-weather, … simply packages starting with gnome- we will use gnome-* like below.

Install Using Wildcards

Install Using Wildcards

We can see those selected packages with selecting lines.

Install Without Upgrading

Installing a package will upgrade if the package is all ready installed. To prevent this situation –no-upgrade option can be provided.

Install Without Upgrading

Install Without Upgrading

Install Specific Version Of Package

Repositories provides different versions of packages. Some times using only specific version of package works. In this situation it can be provided install only specific version like below.

Remove Package Without Configuration

Normally purging packages will remove the packages configuration files  too. To prevent configuration removal use remove parameter like below.

Remove Package Without Configuration

Remove Package Without Configuration

Completely Remove Packages

Package configuration can be removed if its not needed or corrupted.  Purge is the command used to clear configuration of packages.

LEARN MORE  How To Create User Creation Defaults With Skel In Linux?

Completely Remove Packages

Completely Remove Packages

OR alterntively the same operation can be done with remove command by providing –purge option

Clean Apt Cache

Apt command downloads package information and packages in to the cache. This cache get bigger and bigger over time. This local cache or repository must be cleaned regularly with the command below.

Download Only Source Code

As we know packages are compiled from source code and provided as binary. Repositories also provides these source code if the source code option is enable in the /etc/apt/sources.list configuration. Source code can be downloaded like below. Source code in repositories can be enable by un commenting deb-src lines and final look will be like below.

Enable deb source

Enable deb source

Then run apt-get update to get latest information about source packages.

Download Only Source Code

Download Only Source Code

Download And Unpack Package

To make things easier source package can be downloaded and unpacked automatically like below.

Download And Unpack Package

Download And Unpack Package

Download, Unpack and Compile Package

One step further of downloading and extracting package is compiling the package. All these operations can be done automatically with the command below.

Download, Unpack and Compile Package

Download, Unpack and Compile Package

Download Only Package

There are some offline hosts and want to get package for them to install. We will just download package without installing it.

Download Only Package

Download Only Package

Get Change Log Of Package

Package maintainers provides change log of new versions there are different ways to get this change log like from upstream site, maintainers site or simply using changelog package.

Get Change Log Of Package

Get Change Log Of Package

Check Broken Dependencies

Some times it is required to check broken package dependencies.  There is a command named check to accomplish this task.

Check Broken Dependencies

Check Broken Dependencies

Auto Clean

To clear and remove all .deb files from /var/cache/apt/archives use following command. This will give useful disk space for other operations.

Auto Clean

Auto Clean

Auto Remove

To remove package with their dependencies those will not be needed in the future autoremove can be used. This will only remove dependencies which is not used by other packages.

Auto Remove

Auto Remove

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/apt-and-apt-get-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

2 Responses

  1. sachidananda sahu says:

    Hi,

    Really very good summary about apt. I have doubt with “Install Without Upgrading ”

    Why this option is required, as if a package is already downloaded, and we are not upgrading too so why we will reinstall can you give an example for this case.

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)