Do you know about computer software?
Yes, I know the computer, It is the combination of the Software and Hardware but I am talking here software or tools which are installed inside the operating system no matter, OS is window Mac or Linux.
Installing and removing the packages from the Linux operating system is the most popular activity. If you want to be expert in the LINUX operating system you must know about the installing and removing packages.
There are lots of the methods used to manage packages inside Linux. the apt-get method is one of them.
Apt-get is a package manager used to manage packages inside the debian-based operating system, for example, Ubuntu, Kali Linux, Debian, and other debian-based distributions.
This package manager is very useful for Debian based users, It is the command-line tool for managing packages. if you are a Linux lover then you can understand the importance of the command-line tool.
You will learn what is the use of apt-get command including, version, options, repository, update, upgrade, dist-upgrade, autoremove, install, uninstall, remove, purge, clean cache, autoclean, clean packages, search packages, search installed packages and more. The apt-get package manager is command-based utility and available for Debian based operating system only.
Lets talk about more options:
- apt-get options
- apt-get version
- apt-get repository
- apt-get source
- apt-get update
- apt-get upgrade
- apt-get dist-upgrade
- apt-get autoremove
- apt-get install
- apt-get fix-missing
- apt-get reinstall
- apt-get remove
- apt-get purge
- apt-get clean cache
- apt-get clean
- apt-get autoclean
- apt-get search
- apt-get list package
- apt-get search installed
- apt-get command not found
apt-get is a command-line, has many options like install, remove, update, upgrade and dist-upgrade, etc. Each and every option has a different use. If you want to see the complete list of options then use the following command
$sudo apt-get --help #apt-get --help
root@kali:~#apt-get --help apt 1.8.3 (amd64) Usage: apt-get [options] command apt-get [options] install|remove pkg1 [pkg2 ...] apt-get [options] source pkg1 [pkg2 ...] apt-get is a command line interface for retrieval of packages and information about them from authenticated sources and for installation, upgrade and removal of packages together with their dependencies. Most used commands: update - Retrieve new lists of packages upgrade - Perform an upgrade install - Install new packages (pkg is libc6 not libc6.deb) reinstall - Reinstall packages (pkg is libc6 not libc6.deb) remove - Remove packages purge - Remove packages and config files autoremove - Remove automatically all unused packages dist-upgrade - Distribution upgrade, see apt-get(8) dselect-upgrade - Follow dselect selections build-dep - Configure build-dependencies for source packages clean - Erase downloaded archive files autoclean - Erase old downloaded archive files
I am going to use the first option followed by apt-get command. It is –version. It is used to check the version of apt-get command
check the version of apt-get command by using following command
$sudo apt-get –version
root@kali:~#apt-get --version apt 1.8.3 (amd64) Supported modules: *Ver: Standard .deb *Pkg: Debian dpkg interface (Priority 30) Pkg: Debian APT solver interface (Priority -1000) Pkg: Debian APT planner interface (Priority -1000) S.L: 'deb' Debian binary tree S.L: 'deb-src' Debian source tree Idx: Debian Source Index Idx: Debian Package Index Idx: Debian Translation Index Idx: Debian dpkg status file Idx: Debian deb file Idx: Debian dsc file Idx: Debian control file Idx: EDSP scenario file Idx: EIPP scenario file root@kali:~
A repository is a place where all selected software stored by development teams. Mostly different distribution’s organization created its own repository. Kali linux has its own repository, and ubuntu has difference. Similar Kali and Ubuntu, Debian has its own repository.
All the tested software are stored on the server and this is called repository.
Every server has its specific address this address is called source list. You must add this server list into the file /etc/apt/sources.list
I am using kali Linux and The entry of sources.list as following:
root@kali:~#cat /etc/apt/sources.list deb http://http.kali.org/kali kali-rolling main non-free contrib deb-src http://http.kali.org/kali kali-rolling main non-free contrib root@kali:~
apt-get source command is used to download source code from the software developer’s official website. Most of the developers store their code on GitHub
Before to run command source you must add the source mentioned repository.
I am using Kali Linux and want to download the source code of rsync tool. So I run the following command
root@kali:~# mkdir rsync root@kali:~# cd rsync/ root@kali:~/rsync# apt-get source rsync Reading package lists... Done NOTICE: 'rsync' packaging is maintained in the 'Git' version control system at: https://salsa.debian.org/debian/rsync.git Please use: git clone https://salsa.debian.org/debian/rsync.git to retrieve the latest (possibly unreleased) updates to the package. Need to get 939 kB of source archives. Get:1 http://ftp.harukasan.org/kali kali-rolling/main rsync 3.1.3-6 (dsc) [1,877 B] Get:2 http://ftp.harukasan.org/kali kali-rolling/main rsync 3.1.3-6 (tar) [906 kB] Get:3 http://ftp.harukasan.org/kali kali-rolling/main rsync 3.1.3-6 (diff) [30.9 kB] Fetched 939 kB in 9s (105 kB/s) dpkg-source: info: extracting rsync in rsync-3.1.3 dpkg-source: info: unpacking rsync_3.1.3.orig.tar.gz dpkg-source: info: unpacking rsync_3.1.3-6.debian.tar.xz W: Download is performed unsandboxed as root as file 'rsync_3.1.3-6.dsc' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied) root@kali:~/rsync# ls rsync-3.1.3 rsync_3.1.3-6.dsc rsync_3.1.3-6.debian.tar.xz rsync_3.1.3.orig.tar.gz root@kali:~/rsync#
When you have completed adding repositories in sources.list file, your next step to update headers of repository list.
You can run the following commands to update information about available software version stored in the repository
You can run the following commands to update Ubuntu.
$sudo apt-get update
$sudo apt update
You can see the result following:
Linux distributions are combination of the core system and software/tools. The core version is updated from time to time and gives a new name to the operating system. You can say it is a major update of any system.
Core system example: Ubuntu 19.04, 18.08, 18.04, 16.04 15.04 and more.
Kali Linux 1.0.1 now Kali Linux 2019.2 and 2019.3
apt-get upgrade command doesn’t upgrade the core system, It upgrades only software system.
In the upgrade process, system downloads the new version of tools available on system and it will install these new versions of tools in your system. The old version will be removed.
$sudo apt-get upgrade
apt-get dist-upgrade command will upgrade the core system as well as a software system. Everything will we new on your system.
I was using Linux 2019.2, but the new version of Kali Linux had been released. I decided to update Kali Linux in new version as well as its software.
So I used the following command to upgrade the core version as well.
$sudo apt-get dist-upgrade
You can full upgrade by a single command
When you remove the package from Ubuntu, Debian or other Linux system, the dependency package will not remove. It will stay in your Linux system.
When you will run apt-get autoremove command, it will remove unused packages from your computer including dependency and old package. These old packages are not usable anymore when the new package is installed on your computer.
When you upgrade system then apt-get dist-upgrade package installs new packages and old package stay in your system as well.
So don’t forget apt-get autoremove command after upgrading your debian based distribution including Ubuntu, Kali Linux, and Debian.
It removes the package only but doesn’t purge the package
The command is
In the case of sudo user command will be as follow.
$sudo apt-get autoremove
root@kali:~#apt-get autoremove Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: giskismet kali-desktop-common leafpad libcrystalhd3 libdouble-conversion1 libgeos-3.7.1 libhttp-parser2.8 libigdgmm5 libproj13 libtexlua52 libwireshark11 libwiretap8 libwsutil9 python-dicttoxml python-dns python-dnslib python-jsonrpclib python-mockito python-pypdf2 python-slowaes python-unicodecsv python-whoosh python-xlsxwriter suckless-tools 0 upgraded, 0 newly installed, 24 to remove and 11 not upgraded. After this operation, 93.9 MB disk space will be freed. Do you want to continue? [Y/n] root@kali:~
the apt-get install command is used to install new packages on your debian based distribution.
I am going to install acheck on my Kali Linux system
root@kali:~# acheck bash: acheck: command not found root@kali:~# apt-get install acheck Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: acheck-rules libconfig-general-perl libterm-size-perl libtext-aspell-perl The following NEW packages will be installed: acheck acheck-rules libconfig-general-perl libterm-size-perl libtext-aspell-perl 0 upgraded, 5 newly installed, 0 to remove and 22 not upgraded. Need to get 155 kB of archives. After this operation, 446 kB of additional disk space will be used. Do you want to continue? [Y/n] y
After installation, you can see, acheck command is working fine, I am going to see the version of acheck.
root@kali:~# acheck --version acheck version 0.4 root@kali:~#
If you are facing any problem with package then you can reinstall it and fix it.
apt-get reinstall option will remove packages completely from your computer first then it will reinstall the same package again. Remember, the packages that depend on it will not be removed.
In short, it removes the package but not dependencies and again reinstalls the package. If you think installed package is not working properly, you can use this apt-get reinstall command.
The complete command is looking as following
sudo apt-get install –reinstall packagename
apt-get command is used to remove the package. This command removes only package. It doesn’t remove configuration packages and dependency packages
I have installed acheck some time before now I am going to remove it. You can use the following command to remove the pakcage.
$sudo apt-get remove packagename
#apt-get remove packagename
root@kali:~# apt-get remove acheck Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: acheck-rules libconfig-general-perl libterm-size-perl libtext-aspell-perl Use 'apt autoremove' to remove them. The following packages will be REMOVED: acheck 0 upgraded, 0 newly installed, 1 to remove and 22 not upgraded. After this operation, 119 kB disk space will be freed. Do you want to continue? [Y/n]
When you use apt-get purge command to remove package it will uninstall the package with configuration file and other data.
$sudo apt-get purge package_name
#apt-get purge package_name
root@kali:~# apt-get purge acheck Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: acheck-rules libconfig-general-perl libterm-size-perl libtext-aspell-perl Use 'apt autoremove' to remove them. The following packages will be REMOVED: acheck* 0 upgraded, 0 newly installed, 1 to remove and 22 not upgraded. After this operation, 119 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 427160 files and directories currently installed.) Removing acheck (0.5.7) ... Processing triggers for man-db (2.8.7-3) ... root@kali:~#
apt-get clean command is used to clean apt cache
When you use a command to install the package, The command will download the package in the cache first. Later this package will be installed.
These downloaded files are stored in the location /var/cache/apt/archives and /var/cache/apt/archives/partial . You can run the following command to see these downloaded packages
These files stay on your computer whenever you will not remove manually. So keep in mind you should clean cache after installing package. This command can be used from time to time to clean the cache.
You can clean cache by using the following command.
I run du command to check the size of directories after running apt-get autoclean command. The directories sizes are as below:
root@kali:~#du /var/cache/apt/ 4 /var/cache/apt/archives/partial 1867576 /var/cache/apt/archives 1923968 /var/cache/apt/ root@kali:~
root@kali:~#apt-get clean root@kali:~
Again I checked the file size it was as below. You can do this practice by yourself.
root@kali:~#du /var/cache/apt/ 4 /var/cache/apt/archives/partial 100 /var/cache/apt/archives 104 /var/cache/apt/ root@kali:~
autoclean option is similar to clean, It erases the retrieved packages. But the main difference is that this command only removes those packages no longer to be downloaded or largely useless.
This allows a cache to be maintained over a long period without it growing out of control.
Run the following the command and enjoy
root@kali:~#du /var/cache/apt/ 107444 /var/cache/apt/archives/partial 2051368 /var/cache/apt/archives 2107760 /var/cache/apt/ root@kali:~
root@kali:~#apt-get autoclean Reading package lists... Done Building dependency tree Reading state information... Done Del axel 2.17.5-1 [72.7 kB] Del libgcc-8-dev 8.3.0-19 [2,297 kB] Del sysvinit-utils 2.95-5 [82.6 kB] Del runit-helper 188.8.131.52 [5,708 B]
root@kali:~#du /var/cache/apt/ 4 /var/cache/apt/archives/partial 1867576 /var/cache/apt/archives 1923968 /var/cache/apt/ root@kali:~
Most people are searching apt-get search option, In fact apt-get search is not actually working. If you want to search option then you will have to use apt search command.
apt search command is used to search for available pakage on the repository. For Example, I want to install skype on Kali Linux, but I don’t know about its availability. So I will run search command for searching new package for installation.
$sudo apt search Package_name
# apt search Package_name
root@kali:~# apt search skype Sorting... Done Full Text Search... Done empathy-skype/kali-rolling 20140930+svn665+dfsg-1+b1 amd64 Skype plugin for libpurple messengers (Empathy-specific files) hashcat/kali-rolling,now 5.1.0+ds1-1 amd64 [installed,automatic] World's fastest and most advanced password recovery utility libopus-dev/kali-rolling 1.3-1+b1 amd64 Opus codec library development files libopus-ocaml/kali-rolling 0.1.2-2+b1 amd64 OCaml interface to the opus library -- runtime files libopus-ocaml-dev/kali-rolling 0.1.2-2+b1 amd64 OCaml interface to the opus library -- development files libopus0/kali-rolling,now 1.3-1+b1 amd64 [installed,automatic] Opus codec runtime library pidgin-sipe/kali-rolling 1.24.0-1 amd64 Pidgin plugin for Skype for Business and Microsoft Lync pidgin-skype/kali-rolling 20140930+svn665+dfsg-1+b1 amd64 Skype plugin for libpurple messengers (Pidgin-specific files) pidgin-skype-common/kali-rolling 20140930+svn665+dfsg-1+b1 amd64 Skype plugin for libpurple messengers (common files) pidgin-skype-dbg/kali-rolling 20140930+svn665+dfsg-1+b1 amd64 Skype plugin for libpurple messengers (debug symbols) root@kali:~#
Example 2: search for acheck
root@kali:~# apt search acheck Sorting... Done Full Text Search... Done acheck/kali-rolling 0.5.7 all Check common localisation mistakes acheck-rules/kali-rolling,now 0.3.5 all [installed,auto-removable] Basic rules for acheck chktex/kali-rolling 1.7.6-3 amd64 Finds typographic errors in LaTeX lacheck/kali-rolling 1.26-17 amd64 Simple syntax checker for LaTeX libsbt-test-interface-java/kali-rolling 1.0+repack-1 all Sbt test interface lua-check/kali-rolling 0.23.0-1 all static analyzer and a linter for the Lua language scala-library/kali-rolling 2.11.12-4 all Scala standard library root@kali:~#
apt-get list apt list package
For your kind information, this is not apt-get list command, If you want to display available list of particular package then you can run following command
$sudo apt list package_name
#apt list package_name
root@kali:~# apt list skype Listing... Done root@kali:~# apt list teamviewer Listing... Done root@kali:~# apt list acheck Listing... Done acheck/kali-rolling 0.5.7 all
apt-get list installed apt list installed
If you want to check all installed package on your system then you can apt list installed command and it is not apt-get list installed
$sudo apt list –installed
#apt list –installed
root@kali:~# apt list --installed Listing... Done 0trace/kali-rolling,now 0.01-3kali1 amd64 [installed,automatic] aapt/kali-rolling,now 1:8.1.0+r23-3 amd64 [installed,automatic] accountsservice/kali-rolling,now 0.6.45-2 amd64 [installed,automatic] ace-voip/kali-rolling,now 1.10-1kali6 amd64 [installed,automatic] acheck-rules/kali-rolling,now 0.3.5 all [installed,auto-removable] acl/kali-rolling,now 2.2.53-4 amd64 [installed,automatic] adduser/kali-rolling,now 3.118 all [installed] adwaita-icon-theme/kali-rolling,now 3.30.1-1 all [installed,automatic] afflib-tools/kali-rolling,now 3.7.18-3 amd64 [installed,automatic] aglfn/kali-rolling,now 1.7-3 all [installed,automatic] aircrack-ng/kali-rolling,now 1:1.5.2-3 amd64 [installed,automatic] alsa-tools/kali-rolling,now 1.1.7-1 amd64 [installed,automatic] amap/kali-rolling,now 5.4-4kali1 amd64 [installed,automatic]
Problem apt-get command not found
If you run apt-get command and get error “apt-get command not found”, It means the aptitude package is not available in your system.
Then you must install it first then you can run apt-get command
More details apt-get command not found Solved