- Adding and Removing Linux Software
- Adding and Removing Linux Software with «apt» Package Management Tools
- apt vs apt-get
- The Short Version of apt vs apt-get
- The Long Version of apt vs apt-get
- Listing of apt and apt-get commands
- Getting Help with “apt” and “apt-get”
- Installing Linux Software
- Check the Dependencies of a Package
- Search for a Linux Package
- Method #1: “apt-cache”
- Method #2: “apt-search”
- View Linux Package Information
- Verifying a Package for Broken Dependencies
- Updating System Packages
- Upgrade Your System
- Removing Software
- Removing Unused Packages
- Adding Repositories to Your sources.list File
- Directly Modifying sources.list
- Adding Repositories from the Command Line
- Using a GUI-based Installer
- Installing Software from git
Adding and Removing Linux Software
A fundamental task as system administrator is adding and removing Linux software that either didn’t come with the distribution or removing unwanted software to free up hardware space. There are three main methods for modifying software:
- apt package management tools;
- GUI-based installation tools; and,
- Git based methodologies.
If you want to download and compile Linux software packages yourself, give Secur’s Linux Software Management article a read.
Adding and Removing Linux Software with «apt» Package Management Tools
Debian-based Linux distributions use the Advanced Packaging Tool, or apt, for software management. Originally designed as a front-end for the dpkg utility. It is used to install or upgrade all necessary dependent applications so that .deb packages can be installed. In APT, use:
- apt-get to download and install new software packages;
- Update and upgrade software with it.
apt vs apt-get
It is common to see apt install packages instead of the usual apt-get install package and it is worthwhile spending a bit of time learning about the difference. In this article, you will notice that we make use of both “apt” and “apt-get” commands.
The Short Version of apt vs apt-get
The “apt” command is a subset of apt-get and apt-cache commands that provide the basic/ necessary commands for package management and “apt-get” is geared towards the experienced user.
The Long Version of apt vs apt-get
Every component and application installed on a Linux system is built into what is referred to as a “package”; Debian system uses a set of tools called Advanced Packaging Tool (APT) to manage the dpkg packaging system, which installs programs and applications so users avoid the need to compile code from source. In linux, the package file is the basic unit of software and is a compressed collection of metadata and files that comprise the software packages.. Linux package are created by the package maintainer who gets the software in source code form from the author of the program, compiles it, and creates the package metadata, including any installation scripts.
A number of tools interact with APT to allow you to install, remove and manage packages in Debian based Linux distributions.
There are two main tools around APT: apt-get and apt-cache.
apt-get is for installing, upgrading, and cleaning packages,
apt-cache is used for finding new packages.
Most of the commands associated with these two tools are too low level and have so many functionalities never used by an average Linux user and the most commonly used package management commands are scattered across apt-get and apt-cache.
This is where “apt” commands come in; consisting of the most widely used features from apt-get and apt-cache, so you don’t have to bounce between apt-get and apt-cache commands. apt is more structured and provides you with necessary options needed to manage packages. While apt does have some similar command options as apt-get, it’s not backward compatible with apt-get. That means it won’t always work if you just replace the apt-get part of an apt-get command with apt.
Listing of apt and apt-get commands
apt Command | apt-get Command | Command’s Function |
---|---|---|
apt install | apt-get install | Installs package |
apt remove | apt-get remove | Removes package |
apt purge | apt-get purge | Removes package with configuration |
apt update | apt-get update | Refreshes repository index |
apt upgrade | apt-get upgrade | Upgrades all upgradeable packages |
apt autoremove | apt-get autoremove | Removes unwanted packages |
apt full-upgrade | apt-get dist-upgrade | Upgrades packages with auto-handling of dependencies |
apt search | apt-cache search | Searches for the program |
apt show | apt-cache show | Shows package details |
apt list | Lists packages with criteria (installed, upgradable etc) | |
apt edit-sources | Edits sources list |
One point to note here is that apt is under continuous development. So you may see a few new options added to the command in the future versions.
Getting Help with “apt” and “apt-get”
The following command will list you all the options with it’s description on how to use APT on your system.
Installing Linux Software
You can install a package by specifying a single package name. Additionally you can install many packages at once by listing all their names.
Check the Dependencies of a Package
This will help you to display raw information about dependencies of a particular package, in this case, NGINX.
Search for a Linux Package
Method #1: “apt-cache”
Before downloading a software package, check whether the package you need is available from your repository with the apt tool. The syntax “apt-cache search keyword”. Use the apt-cache command to search the apt cache and the places it stores the package names; numerous files may contain the keyword you are looking for.
Method #2: “apt-search”
The search option searches for the given package name, NGINX and show the matching packages.
View Linux Package Information
Displays information about the nginx package.
Verifying a Package for Broken Dependencies
Sometimes during package installation, you may get errors concerning broken package dependencies, to check that you do not have these problems run the command below with the package name. Be sure to use the “-v” switch.
Updating System Packages
Software repositories will be periodically updated with new software or new versions of existing software. These updates don’t reach you automatically, so you have to request them in order to apply these updates to your own system. This involves downloading a list of packages from different repositories included on your system .
Updating isn’t the same as upgrading: updating simply updates the list of packages available for download from the repository, whereas upgrading will upgrade the package to the latest version in the repository. You can update your individual system by entering the apt/apt-get command followed by the keyword update. This will search through all the packages on your system and check whether updates are available. If so, the updates are downloaded.
Upgrade Your System
This helps you to install new versions of all the packages on your system. Since upgrading packages makes changes to your software, you must be logged in as root or use the sudo command before entering apt/apt-get upgrade. This can take a long time depending on how long it has been since the last upgrade.
Removing Software
When removing software, use apt-get/apt command with the remove option, followed by the name of the software to remove. The removal task is done in real time and asks if you want to continue. The remove command doesn’t remove the configuration files, which means you can reinstall the same package in the future without reconfiguring. If you do want to remove the configuration files at the same time as the package, you can use the purge option “apt purge nginx”
Removing Unused Packages
Installing a new package on your system means installing it’s dependencies, and they use some of the same system libraries with other packages. Then, after removing that particular package, it’s dependencies will remain on the system, so you may want to remove them by using autoremove. You will see these dependencies removed in real time.
Adding Repositories to Your sources.list File
The servers that hold software for particular distributions of Linux are known as repositories and are stored in the sources.list file. Although these repositories often contain the same or similar software, they aren’t identical to one another and they sometimes have different versions of the same software or entirely different software. When you download a new software package to your computer, Linux looks sequentially through your repositories listed in sources.list and stops when it finds the desired package.
Avoid using testing, experimental, or unstable repositories in your sources.list because they can download problematic software to your system. Software that isn’t fully tested might break your system.
You may want to add a backup repository that your system can search through in case it doesn’t find it a specific software in your preferred repository. If you are using Kali Linux like we are for this tutorial, the Kali developers offer the following guidance:
- If you want to install additional tools and software outside of the core Kali distribution, not alter /etc/apt/sources.list, as this is used for the Kali Linux Operating System.
- Place extra tools and software in their own file (each mirror should have its own file) in the directory /etc/apt/sources.list.d/ (such as /etc/apt/sources.list.d/repo-name.list, replacing repo-name with the mirror name). It is highly recommended that each mirror should be in its own file.
- Modify the sources.list file to define from which repositories you want to download software from.
- Add a repo from the command line
Directly Modifying sources.list
Find the sources.list file at /etc/apt/sources.list and open it with any text editor.
In this situation, we are working on a Kali Linux system and opened the sources.list file with nano. The format for this is as follows:
deb (The “Archive“) http://http.kali.org/kali (The “Mirror“) kali-rolling (The “Branch“) main non-free contrib (The “Component“)
Archive: going to be deb (Regular Binary) or deb-src (Source), depending if you want a package or the source of the package;
Mirror: Should be http.kali.org/kali, which will direct you to the best mirror;
Branch: What version of Kali you wish to use; and,
Component: Which packages you wish to use,
Then simply add the repository name to the list and save the file.
Many Linux distributions divide repositories into separate categories. Ubuntu breaks out its repository categories as follows:
main: Contains supported open source software
Universe: Contains community-maintained open source software
Multiverse: Contains software restricted by copyright or other legal issues
restricted: Contains proprietary device drivers
Backports: Contains packages from later releases
Adding Repositories from the Command Line
In order to be able to install the software contained within a repository, the repository must be added to your machine. In a Debian based distribution, this can be done by running the command “sudo apt-add-repository”. This creates a new file in the directory /etc/apt/sources.list.d/, then run “apt update” to update your local version of the software.
Using a GUI-based Installer
A common GUI-based installation tool for Linux is Synaptic. Synaptic, based on APT, lets users search for packages across a variety of repositories and install them a few clicks. Synaptic also filters out packages that will not run on your current system due to architecture differences. You will notice that at the time of writing, there are close to 73,000 packages:
Some of the features Synaptic offers are:
- Install, remove, and upgrade packages;
- Upgrade your whole system;
- Search and filter the list of available packages;
- Perform smart system upgrades;
- Fix broken package dependencies; and,
- Edit the list of used repositories (sources.list).
Now you can search for the package you’re looking for. Click the Search tab to open a search window. Because you are looking for “Chess”, enter chess into the search window and click Search.
Scroll down the search results to find the package you’re looking for. Check the box next to it and then click the Apply tab, Once you’ve found the package you would like to install, select the checkbox next to it and choose Mark for installation:
If the package requires the installation of other packages, choose Mark to install them as well:
After hitting “Mark” you will be taken back to the main interface. Click “Apply”:
You will be asked to review the changes and click apply again Once done, Synaptic downloads the packages and applies the changes.
Installing Software from git
If the software you want isn’t available in any of the repositories, it may be on github a site that allows developers to share their software with others to download, use, and provide feedback.
Once you’ve found the software on github, you can install it from the terminal by entering the git clone command followed by its github URL, so if you want to install the The Exploit Database Git Repository from git, do the following:
git clone https://github.com/offensive-security/exploitdb.git /opt/exploitdb
- Clone the repository;
- Add the binary into $PATH;and
- Edit the config file to reflect the git path.
- $ sudo git clone https://github.com/offensive-security/exploitdb.git /opt/exploitdb
- $ sudo ln -sf /opt/exploitdb/searchsploit /usr/local/bin/searchsploit
The git clone command copies all the data and files from that location onto your system. You can check to see that they’ve been successfully downloaded by using the long listing command ls –l on the target directory and if you’ cloned searchsploit to your system, you should see it in the directory, like you do below: