Concept of Installing Applications in Ubuntu

Until now we have discussed how to install Ubuntu, concepts around files, keyboard shortcuts to navigate easily and various ways to customize Ubuntu with Gnome shell. Today I am going to discuss how to install applications in Linux along with the various ways to do them, and will end with a special note that would explain how “running” applications in Ubuntu is fundamentally different than Windows.
You must be used to installing softwares in Windows by downloading .EXE files or .MSI installers. You open these files and click Next -> Next and viola. Installing applications in Ubuntu is a bit different and safer than Windows in some cases. But before we get into the steps its important to understand the concept of Packages in Ubuntu.

What is a Package?

A package can be considered a collection of files bundled into a single file. Package contains among other things, the installation script which tells where the files will be copied and what settings needs to be changed once the package is installed.
In essence, the output of a package is equivalent to .exe or .msi installers, that is they install a software on the OS. There are many ways to install a package on Linux. You can install a package using Package manager which itself are categorized in Low-Level and High-Level package managers. You can also download packages over the Internet and use it to install it on the system (more on this later in this article).
Low level package managers are dpkg (for Debian based Linux like Ubuntu) and rpm (for SUSE and Fedora). While high level package managers are apt-get (for Debian), zypper (for SUSE) and yum (for Fedora).
Packages can depend on other package to be installed first. Say if you want to install some software which was written in PHP, you may need to install the PHP package first. This concept is called dependency and is usually taken care of itself if you are using a high level package managers.

Advanced Packaging Tool (APT)

The underlying package manager in Ubuntu (or any Debian based Linux) is APT. You can use the command apt to install or remove packages on your system. APT is also used in background in GUI based package managers like Ubuntu Software Center and synaptic.
EDX have a pdf which lists some basic commands to using package managers. Download it here.

What is Source and Binary?

Source refers to the source code of a software which you can compile and build on your own PC and then use it. Binary refers to the compiled code and which can be straightaway installed on your PC. While the Source is machine independent, Binary is not. Two binaries can be different depending on which PC it was compiled on. Binary is akin to .EXE files in Windows. So wherever you read “binary” in context to Ubuntu, it’s talking about the ‘compiled code‘ which can be ‘installed‘.

Software Channels/Repositories

When we say we can install packages from the Terminal using command like apt-get we mean software can be installed by fetching files over the Internet. So where does these files reside? What is the source of these packages? Excellent question.

Ubuntu stores all of its packages in locations called software channels or repositories. A software channel is simply a location which holds packages of similar types, which can be downloaded and installed using a package manager. A package manager will store an index of all of the packages available from a software channel. You can update this index using command apt-get update.

There are four Ubuntu software channels – Main, Restricted, Universe and Multiverse. Each has a different purpose. By default, only packages from Main and Restricted can be installed. To use packages from Universe or Multiverse, you just need to put a tick against the options in Software and Updates settings (as shown in the screenshot below).

Software Channel

Installing downloaded packages

It’s one of the most confusing aspects that I faced while doing. I knew how to install applications from terminal using apt-get. But once I downloaded a .deb package from Internet, I wasn’t able to install it by just double clicking and expecting a wizard to click “Next” in hopes to get it installed. The way installing packages works on Ubuntu is a bit different, and I would be trying to explain it here by discussion various ways to install a package.
Lets see an example of a .deb package of Chromium, an open source browser which forms the basis of other browsers like Chrome and Opera. You can get the .deb package for Chromium from here. (Direct link for Chromium 64 bit for Ubuntu).

Method 0: Using Terminal

If you wanted to install Chromium using terminal you could have used following command, which also requires you to be online:

sudo apt-get install chromium-browser

Method 1: Using Software Center

Double click the .deb file and it should open in “Ubuntu Software Center”. Here on, you can just click “Install” and the software will be installed in a jiff.

Method 2: Using GDebi

GDebi is a package installer that can be used to install .deb packages. Open Terminal, type gdebi and press enter. If GDebi is installed you will see a bunch of options to use it or else you will get “command not found“.
Open Terminal and enter following command to install GDebi. If it’s already installed it will say, “gdebi is already the newest version” and if it’s not it will install it for you.

sudo apt-get install gdebi

Now we are ready to use GDebi to install Chromium. Which again has two ways:
A. Using Terminal: Open terminal and go to location where you downloaded the Chromium .deb package. By default it should be your downloads folder.

cd ~/Downloads

Now use the command to install Chromium using GDebi:

sudo gdebi my_package_name.deb

B. Using GUI version of GDebi: Right click the .deb package and select, Open with -> “GDebi Package Manager“. As soon as you do that, GDebi will be open in the form of GUI and the chromium package will be opened for your analysis. You can see the files inside the package and the instructions that are written inside it. If you click “Details” button you can also see the dependency of the package, which would be required before you can install this package. In our case, since we are trying to install Chromium, its package will show “chromium-codecs-ffmpeg-extra” as the dependency.
Now to install the Chromium just press “Install Package” button. A progress bar will be shown during the install. You can also click “Terminal” arrow to see what is happening in the background. Here you will notice that the “chromium-codecs-ffmpeg-extra” dependency was installed before Chromium package was installed.

Installation finished for Chromium through GDebi
Installation finished for Chromium through GDebi

Other ways to Install Packages:

There are many other and geeky ways to install an application in Linux.  Then there are “.tar.gz” packages which is just a compressed file like .zip or .rar and which can contain binary file or source code. You can use this source code to compile and create your own binary, which is of course advanced stuff. Checkout links at bottom for guides to learn more.
Synaptic Package Manager, which is a UI based manager that  can be used to install various packages. Synaptic can also be used to convert .rpm package (which are package for other linux distribution) to .deb and then install it, which may not work for every .deb package though.
Here you can learn about Personal Package Archives (PPAs) and how to install packages using it.
There is a way to install applications right from your browser. Why? Cause it’s simple.
Compiling Source code itself and creating your own binary. Why? Cause it’s uber cool.
Along with other things the article talks about how to backup your packages, in case you want to install same packages on other PC without the need to download them again, or if you just want to keep the list of installed packages for backup purpose.

Finding Softwares (Packages)

There will be scenarios where you would like to find the locations where the files related to packages you installed are kept. In general, executable programs should live in the /bin, /usr/bin, /sbin, /usr/sbin directories or under /opt. But which, whereis and locate commands is all you need most of the time to search precisely the location of a package or files across any location and works faster than find feature in Windows.
Let’s see how you can Ctrl + F anything right from the Terminal!

1. which command

One way to locate programs is to use the which command. For example, to find out exactly where the firefox program is on your PC:

$ which firefox

2. whereis command

If which does not find the program, whereis is a good alternative because it looks for packages in a broader range of system directories:

$ whereis firefox
firefox: /usr/bin/firefox /etc/firefox /usr/lib/firefox /usr/bin/X11/firefox /usr/share/man/man1/firefox.1.gz

3. locate command

This command not only finds package locations, but it can find any file based on the file name and supports wildcards. An example would be:

$ locate *.sys

Uninstalling Packages

Yea, so you have installed many packages then you initially intended. Now how to get rid of some? In Windows you are familiar with the “Add/Remove Programs” or “Programs and Features” if you have decided to upgrade from XP. But how to remove packages from Ubuntu and making sure you don’t mess up? Fortunately uninstalling software (or removing packages) is easy.

1. Using Ubuntu Software Center

Just open Ubuntu Software Center, navigate to the software which you want to install OR search for it in the search box. Then click “Remove” and after asking from you the password, the package will be removed.

2. Using Terminal

You would have to know the name of the package which you want to remove from your system. To remove Chromium from terminal we would use following command:

sudo apt-get remove chromium-browser

3. Purge it!

sudo apt-get purge chromium-browser

The purge command is used instead of remove if you want to remove the config files associated with the package. remove command only removes the binary. So if you are sure you won’t re-install the package again and want to remove the config files as well (usually stored in your home directory) you can purge it.

Special Note:

As promised, I would like to end this article by an observations, which have to be taken care of if you are dealing with installing and uninstalling packages in Ubuntu (or generally in Linux).
Do this: Install Chromium again (if you have removed it). Now open Chromium from applications list. Keeping the browser open, go to Terminal and remove the package though “sudo apt-get remove chromium-browser” command. You can also try to  remove it from “Ubuntu Software Center”. Did you notice something? The Chromium browser you kept open isn’t close. In fact Ubuntu didn’t even show a warning about the browser being open. It just removed the package from existence.
In Windows, to uninstall an application, you first have to close the process. This is fundamental to Windows, since it keeps the executable file locked. After this observation I came to realize Ubuntu works differently. In Ubuntu running process is in memory and it doesn’t lock the executable file locked. Some argue that it’s the feature of Ubuntu. I think it’s by design. In Linux, executable files are not defined by “extensions”. It’s defined by permissions and the executable flag. If I have a permission to execute a file, the file’s content is loaded into memory and file is kept free for other user to use. I think due to very nature of Ubuntu to allow multiuser capability, the file is not kept locked after it’s content is loaded into memory and instructions are executed.
If you guys have any other theory or fact, do post it in comments. I would like to know if my observations are different.

Leave a Reply

Your email address will not be published. Required fields are marked *